handling search

This commit is contained in:
Antoine M 2024-12-02 12:29:28 +01:00
parent 6bcc5a0499
commit de37ae1e7d

View File

@ -31,17 +31,18 @@ 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') {
@ -53,8 +54,6 @@ function build_search_artisan_posts_cards($request)
);
}
do_action('wpml_switch_language', $currentLanguage);
$args = array(
@ -65,9 +64,10 @@ function build_search_artisan_posts_cards($request)
"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 = "<div class='no-results'><h3>" . __("Aucun résultat trouvé", "metiers-patrimoine-theme") . "</h3><p>" . __("Essayez d'ajouter un filtre supplémentaire pour trouver plus de résultats", "metiers-patrimoine-theme") . "</p></div>";
}
$response_data = array(
'html_template' => $html_template,
'total_posts_found' => $newsPostsDatas->found_posts,
@ -131,9 +136,11 @@ function debugQueryTest()
"status" => "publish",
"post_type" => "artisans",
"posts_per_page" => -1,
"tax_query" => $taxQuery,
"meta_query" => $metaQuery,
// "tax_query" => $taxQuery,
// "meta_query" => $metaQuery,
's' => "Atelier Schrauwen",
);
$newsPostsDatas = new WP_Query($args);
// write_log($newsPostsDatas->posts);
}
// debugQueryTest();
debugQueryTest();