diff --git a/core/imageboard/search.php b/core/imageboard/search.php index f5f4c7c66..34f0dcc86 100644 --- a/core/imageboard/search.php +++ b/core/imageboard/search.php @@ -174,7 +174,7 @@ public static function count_images(array $tags = []): int $total = $cache->get($cache_key); if (is_null($total)) { [$tag_conditions, $img_conditions, $order] = self::terms_to_conditions($tags); - $querylet = self::build_search_querylet($tag_conditions, $img_conditions, $order); + $querylet = self::build_search_querylet($tag_conditions, $img_conditions, null); $total = (int)$database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables); if (SPEED_HAX && $total > 5000) { // when we have a ton of images, the count @@ -240,7 +240,7 @@ private static function terms_to_conditions(array $terms): array private static function build_search_querylet( array $tag_conditions, array $img_conditions, - string $order, + ?string $order = null, ?int $limit = null, ?int $offset = null ): Querylet { @@ -414,7 +414,9 @@ private static function build_search_querylet( $query->append(new Querylet($img_sql, $img_vars)); } - $query->append(new Querylet(" ORDER BY ".$order)); + if(!is_null($order)) { + $query->append(new Querylet(" ORDER BY ".$order)); + } if (!is_null($limit)) { $query->append(new Querylet(" LIMIT :limit ", ["limit" => $limit]));