diff --git a/includes/api.php b/includes/api.php index ffac30e..0c3ce16 100644 --- a/includes/api.php +++ b/includes/api.php @@ -31,19 +31,20 @@ function build_search_artisan_posts_cards($request) $taxonomyIds = explode(',', $StringifiedTaxonomyIds); $taxonomyIds = array_map('intval', $taxonomyIds); - + $search_value = sanitize_text_field($request->get_param('search')) ?? null; $activePage = is_numeric($previousActivePage) ? $previousActivePage + 1 : 1; - $taxQuery = array( - array( + $taxQuery = []; + if ($taxonomy && !empty($taxonomyIds)) { + $taxQuery[] = array( 'taxonomy' => $taxonomy, 'terms' => $taxonomyIds, 'field' => 'term_id', - ) - ); + ); + } $metaQuery = []; - + if ($localisation && $localisation !== 'all') { $localisationArray = explode(',', $localisation); // Séparer les localisations par des virgules $metaQuery[] = array( @@ -53,8 +54,6 @@ function build_search_artisan_posts_cards($request) ); } - - do_action('wpml_switch_language', $currentLanguage); $args = array( @@ -62,12 +61,13 @@ function build_search_artisan_posts_cards($request) "post_type" => "artisans", "posts_per_page" => -1, "paged" => $activePage, - "tax_query" => $taxQuery, + "tax_query" => $taxQuery, // "meta_query" => [], "meta_query" => $metaQuery, - + 's' => $search_value, ); $newsPostsDatas = new WP_Query($args); + // write_log($newsPostsDatas->posts); ob_start(); @@ -95,6 +95,11 @@ function build_search_artisan_posts_cards($request) $html_template = ob_get_clean(); + + + if ($newsPostsDatas->found_posts === 0) { + $html_template = "
" . __("Essayez d'ajouter un filtre supplémentaire pour trouver plus de résultats", "metiers-patrimoine-theme") . "