Compare commits
4 Commits
e16a195f03
...
a50612cd58
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a50612cd58 | ||
|
|
5e24ce4c88 | ||
|
|
9e14ec6ee7 | ||
|
|
f08f6d1aab |
|
|
@ -7,18 +7,13 @@ add_action('rest_api_init', function () {
|
||||||
-----------------*/
|
-----------------*/
|
||||||
|
|
||||||
// ################ BUILD ARTISANS SEARCH RESULTS ################
|
// ################ BUILD ARTISANS SEARCH RESULTS ################
|
||||||
|
|
||||||
// * BUILD MORE NEWS CARDS
|
|
||||||
register_rest_route('metiers-patrimoine-datas/v1/build', '/artisans', array(
|
register_rest_route('metiers-patrimoine-datas/v1/build', '/artisans', array(
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
'callback' => 'build_search_artisan_posts_cards',
|
'callback' => 'build_search_artisan_posts_cards',
|
||||||
'permission_callback' => '__return_true',
|
'permission_callback' => '__return_true',
|
||||||
));
|
));
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// ################ ARTISANS ################
|
|
||||||
|
|
||||||
|
|
||||||
function build_search_artisan_posts_cards($request)
|
function build_search_artisan_posts_cards($request)
|
||||||
{
|
{
|
||||||
|
|
@ -66,10 +61,10 @@ function build_search_artisan_posts_cards($request)
|
||||||
"meta_query" => $metaQuery,
|
"meta_query" => $metaQuery,
|
||||||
's' => $search_value,
|
's' => $search_value,
|
||||||
);
|
);
|
||||||
$newsPostsDatas = new WP_Query($args);
|
$searchArtisans = new WP_Query($args);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
foreach ($newsPostsDatas->posts as $key => $post) {
|
foreach ($searchArtisans->posts as $key => $post) {
|
||||||
|
|
||||||
// continue en fonction
|
// continue en fonction
|
||||||
$post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-artisans__thumbnail')) ?? null;
|
$post_thumbnail = get_the_post_thumbnail($post->ID, 'full', array('class' => 'card-artisans__thumbnail')) ?? null;
|
||||||
|
|
@ -94,7 +89,7 @@ function build_search_artisan_posts_cards($request)
|
||||||
$html_template = ob_get_clean();
|
$html_template = ob_get_clean();
|
||||||
|
|
||||||
|
|
||||||
if ($newsPostsDatas->found_posts === 0) {
|
if ($searchArtisans->found_posts === 0) {
|
||||||
ob_start();
|
ob_start();
|
||||||
get_template_part(
|
get_template_part(
|
||||||
'template-components/artisans/artisan-search-no-results',
|
'template-components/artisans/artisan-search-no-results',
|
||||||
|
|
@ -105,49 +100,15 @@ function build_search_artisan_posts_cards($request)
|
||||||
}
|
}
|
||||||
$response_data = array(
|
$response_data = array(
|
||||||
'html_template' => $html_template,
|
'html_template' => $html_template,
|
||||||
'total_posts_found' => $newsPostsDatas->found_posts,
|
'total_posts_found' => $searchArtisans->found_posts,
|
||||||
'active_page' => $activePage,
|
'active_page' => $activePage,
|
||||||
'max_num_pages' => $newsPostsDatas->max_num_pages,
|
'max_num_pages' => $searchArtisans->max_num_pages,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$response = new WP_REST_Response($response_data);
|
$response = new WP_REST_Response($response_data);
|
||||||
|
|
||||||
$response->set_status(200);
|
$response->set_status(200);
|
||||||
// debugQueryTest( );
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function debugQueryTest()
|
|
||||||
{
|
|
||||||
|
|
||||||
$args = array(
|
|
||||||
"post_status" => "publish",
|
|
||||||
"post_type" => "artisans",
|
|
||||||
"posts_per_page" => -1,
|
|
||||||
// "tax_query" => $taxQuery,
|
|
||||||
// "meta_query" => $metaQuery,
|
|
||||||
's' => "Atelier Schrauwen",
|
|
||||||
);
|
|
||||||
$newsPostsDatas = new WP_Query($args);
|
|
||||||
$filteredPosts = [];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
do_action('wpml_switch_language', 'nl');
|
|
||||||
ob_start();
|
|
||||||
get_template_part(
|
|
||||||
'template-components/artisans/artisan-search-no-results',
|
|
||||||
null,
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
$html_template = ob_get_clean();
|
|
||||||
$test = __("Aucun résultat trouvé", "metiers-patrimoine-theme");
|
|
||||||
return ($html_template);
|
|
||||||
}
|
|
||||||
// debugQueryTest();
|
|
||||||
|
|
||||||
// add_action('wp_footer', 'debugQueryTest');
|
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,13 @@
|
||||||
@apply text-patrimoine-sante-securite;
|
@apply text-patrimoine-sante-securite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cta {
|
||||||
|
@apply px-4 py-2;
|
||||||
|
&--rounded {
|
||||||
|
@apply rounded-full;
|
||||||
|
}
|
||||||
|
&--primary {
|
||||||
|
@apply bg-patrimoine-sante-securite text-white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@
|
||||||
p {
|
p {
|
||||||
@apply text-neutral-900 tracking-wide;
|
@apply text-neutral-900 tracking-wide;
|
||||||
}
|
}
|
||||||
|
#reset-all-artisans-button {
|
||||||
|
@apply mt-4 mx-auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.card-artisans {
|
.card-artisans {
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,24 @@ function observeSearchResetButton() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function observeResetAllArtisansButton() {
|
||||||
|
const resetAllArtisansButton = document.querySelector('#reset-all-artisans-button');
|
||||||
|
resetAllArtisansButton.addEventListener('click', () => {
|
||||||
|
resetSearchfield();
|
||||||
|
hydrateWithAllArtisans({});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function observeNoResultsApparition() {
|
||||||
|
const grid = document.querySelector('.artisans-posts__grid');
|
||||||
|
|
||||||
|
const observer = new MutationObserver(() => {
|
||||||
|
const noResults = grid.querySelector('.no-results');
|
||||||
|
if (!noResults) return;
|
||||||
|
|
||||||
|
observeResetAllArtisansButton();
|
||||||
|
});
|
||||||
|
observer.observe(grid, { childList: true, subtree: true });
|
||||||
|
}
|
||||||
function clearAllCheckboxes() {
|
function clearAllCheckboxes() {
|
||||||
const filtersCheckboxes = document.querySelectorAll('.taxonomy-checkbox');
|
const filtersCheckboxes = document.querySelectorAll('.taxonomy-checkbox');
|
||||||
|
|
||||||
|
|
@ -219,7 +237,7 @@ export default function dynamicSearch() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const searchForm = document.querySelector('.artisan-search-bar');
|
const searchForm = document.querySelector('.artisan-search-bar');
|
||||||
|
|
||||||
searchForm.addEventListener('submit', handleSearchSubmit);
|
searchForm.addEventListener('submit', handleSearchSubmit);
|
||||||
observeSearchResetButton();
|
observeSearchResetButton();
|
||||||
|
observeNoResultsApparition(); // Si la div no-results apparait, on observe le bouton reset all artisans pour gérer son comortement
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,7 @@
|
||||||
<img class='no-results__cover' src="<?php echo get_stylesheet_directory_uri() . "/resources/img/illustrations/Homegrade_resultats-filtres-cactus.svg" ?>" alt='' />
|
<img class='no-results__cover' src="<?php echo get_stylesheet_directory_uri() . "/resources/img/illustrations/Homegrade_resultats-filtres-cactus.svg" ?>" alt='' />
|
||||||
<h3><?php echo __("Aucun artisan correspondant actuellement", "metiers-patrimoine-theme") ?> </h3>
|
<h3><?php echo __("Aucun artisan correspondant actuellement", "metiers-patrimoine-theme") ?> </h3>
|
||||||
<p> <?php echo __("Sélectionnez un ou plusieurs <span class='highlighted-purple'>métiers</span> ou <span class='highlighted-purple'>critères</span> pour lancer votre recherche", "metiers-patrimoine-theme") ?></p>
|
<p> <?php echo __("Sélectionnez un ou plusieurs <span class='highlighted-purple'>métiers</span> ou <span class='highlighted-purple'>critères</span> pour lancer votre recherche", "metiers-patrimoine-theme") ?></p>
|
||||||
|
<button class="cta cta--primary cta--rounded" id="reset-all-artisans-button">
|
||||||
|
<?php echo __("Voir tous les artisans", "metiers-patrimoine-theme") ?>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -22,7 +22,7 @@ $hasEmptyTaxos = (empty($elementsBatimentsTerms) && empty($metiersTerms)) ? 'car
|
||||||
</div>
|
</div>
|
||||||
<div class="taxonomy-tags card-taxonomies__taxonomy-tags">
|
<div class="taxonomy-tags card-taxonomies__taxonomy-tags">
|
||||||
<?php foreach ($elementsBatimentsTerms as $key => $term) : ?>
|
<?php foreach ($elementsBatimentsTerms as $key => $term) : ?>
|
||||||
<span class="taxonomy-tag"><?php echo $term->name; ?></span>
|
<span class="taxonomy-tag taxonomy-tag--<?php echo $term->parent === 0 ? 'parent' : 'child'; ?>"><?php echo $term->name; ?></span>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user