handling search
This commit is contained in:
parent
6bcc5a0499
commit
de37ae1e7d
|
|
@ -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(
|
||||
|
|
@ -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 = "<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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user