$active_axe ?: null, 'date_from' => $active_date_from ?: null, 'date_to' => $active_date_to ?: null, ]); $redir_url = $redir_params ? add_query_arg( $redir_params, get_category_link( $cat_obj->term_id ) ) : get_category_link( $cat_obj->term_id ); wp_redirect( $redir_url, 301 ); exit; } } // Determine active rubrique $active_rubrique_id = thalim_archive_active_rubrique($active_cat_id); $context['active_rubrique'] = $active_rubrique_id; // Base filter params preserved across all filter links $base_filter_params = array_filter([ 'axe' => $active_axe ?: null, 'date_from' => $active_date_from ?: null, 'date_to' => $active_date_to ?: null, ]); // Build tax_query: exclude séances + optional category filter $tax_query = [ 'relation' => 'AND', [ 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $excluded_cat_ids, 'operator' => 'NOT IN', ], ]; if ($active_cat_id) { $tax_query[] = [ 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => [$active_cat_id], 'include_children' => !$filter_autres, ]; } $query_args = [ 'post_type' => 'post', 'posts_per_page' => 12, 'orderby' => 'date', 'order' => 'DESC', 'tax_query' => $tax_query, 'thalim_event_date_order' => true, ]; if ($active_axe) { $query_args['meta_query'] = [[ 'key' => 'axes_thematiques', 'value' => $active_axe, 'type' => 'NUMERIC', ]]; } if ($active_date_from || $active_date_to) { $query_args['thalim_event_date_filter'] = ['from' => $active_date_from, 'to' => $active_date_to]; } // Axes thématiques for filter dropdown $axes_groups = thalim_get_axes_filter_groups(); $current_axes = $axes_groups[0]['terms'] ?? []; $context['filter_axes'] = $current_axes; // Rubrique/catégorie filter links (stay on this page with filter_cat param) $page_url = get_permalink(); $all_cats = get_categories(['taxonomy' => 'category', 'hide_empty' => false, 'exclude' => $excluded_cat_ids]); // Liens de filtre : navigation vers la page de catégorie, en conservant axe/dates $make_cat_link = function ($cat) use ($base_filter_params) { return $base_filter_params ? add_query_arg($base_filter_params, get_category_link($cat->term_id)) : get_category_link($cat->term_id); }; $context['filter_parents'] = thalim_archive_filter_parents($all_cats, $make_cat_link); $filter_categories = thalim_archive_filter_children($all_cats, $active_rubrique_id, $make_cat_link); // Add "Autres" entry if active rubrique has posts directly assigned to it if ($active_rubrique_id && !empty($filter_categories) && thalim_rubrique_has_direct_posts($active_rubrique_id)) { $params = array_filter(array_merge($base_filter_params, ['filter_cat' => $active_rubrique_id, 'filter_autres' => 1])); $filter_categories[] = thalim_archive_autres_entry(add_query_arg($params, $page_url)); } $context['filter_categories'] = $filter_categories; $posts = Timber::get_posts($query_args); $context['cards'] = thalim_get_cards_data($posts); $context['posts'] = $posts; Timber::render('page-annonces.twig', $context);