FEATURE Add support for filtering posts by etiquette in post grid when page is loaded with a query var
This commit is contained in:
parent
1ff55bb638
commit
257673bb2e
|
|
@ -3,21 +3,43 @@ $post_amount = $args['post_amount'] ?? -1;
|
||||||
$grid_title = $args['grid_title'] ?? 'Trouver une publication';
|
$grid_title = $args['grid_title'] ?? 'Trouver une publication';
|
||||||
$current_post_type = $args['current_post_type'] ?? get_post_type();
|
$current_post_type = $args['current_post_type'] ?? get_post_type();
|
||||||
|
|
||||||
$posts_query = new WP_Query(array(
|
// Récupérer le paramètre etiquette de l'URL
|
||||||
|
$etiquette_slug = isset($_GET['etiquette']) ? sanitize_text_field($_GET['etiquette']) : '';
|
||||||
|
|
||||||
|
|
||||||
|
// Construire les arguments de la query
|
||||||
|
$query_args = array(
|
||||||
'post_type' => $current_post_type,
|
'post_type' => $current_post_type,
|
||||||
'posts_per_page' => $post_amount
|
'posts_per_page' => $post_amount,
|
||||||
));
|
'post_status' => 'publish',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Si on a une étiquette, ajouter le filtre taxonomy
|
||||||
|
if (!empty($etiquette_slug)) {
|
||||||
|
$query_args['tax_query'] = array(
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'etiquettes',
|
||||||
|
'field' => 'slug',
|
||||||
|
'terms' => $etiquette_slug,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$posts_query = new WP_Query($query_args);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<section class="post-grid content-section">
|
<section class="post-grid content-section <?php echo !empty($etiquette_slug) ? 'has-initial-filter' : '' ?>">
|
||||||
<h2 class="find-publication__title title-small"><?php echo $grid_title; ?></h2>
|
<h2 class="find-publication__title title-small"><?php echo $grid_title; ?></h2>
|
||||||
<div class="content-section__inner">
|
<div class="content-section__inner">
|
||||||
|
|
||||||
<?php get_template_part('template-parts/components/archive/post-grid-toolbar', null, array(
|
<?php get_template_part('template-parts/components/archive/post-grid-toolbar', null, array(
|
||||||
'posts_query' => $posts_query,
|
'posts_query' => $posts_query,
|
||||||
'current_post_type' => $current_post_type,
|
'current_post_type' => $current_post_type,
|
||||||
)); ?>
|
'etiquette_active_filter_slug' => $etiquette_slug,
|
||||||
|
)); ?>
|
||||||
|
|
||||||
<ul class="post-grid__list">
|
<ul class="post-grid__list">
|
||||||
<?php if (isset($posts_query) && $posts_query->have_posts()) : ?>
|
<?php if (isset($posts_query) && $posts_query->have_posts()) : ?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user