Answer the question
In order to leave comments, you need to log in
WordPress. Why does the taxonomy post filter only show posts for the first taxonomy?
Created custom_post_type (programs) and taxonomy (genretax). Now I want to display records on the archive-programs.php page depending on the taxonomy specified for them.
The layout uses the MixItUp 3 library (for the tile filter) https://www.kunkalabs.com/mixitup/ Now it looks like this:
And the problem is actually this:
if I specify several taxonomy names for one post (for example, scenic flights and heliskiing ) and for another post I will also indicate scenic flights and heliskiing in the taxonomies, then when filtering (when to choose heliskiing) there are no posts. That is, when each post is given a different taxonomy name, then everything is correct, and if they are the same, then it displays the first post .. For example,
1. Post "HELI-SKI WEEK IN WISTLER" -> taxonomy "Scenic flights";
2. Post "7 Days of Adventure in Hawaii" -> "Scenic Flights" taxonomy and "Private Tour" taxonomy ;
In this case, when clicking on the taxonomy "Scenic flights" will display posts 1 and 2, and when clicking on the taxonomy "Private tour" will not display anything.
Taxonomy output code:
<ul class="programs_list dark_icon_programs">
<?php $terms = get_terms('genretax');
foreach($terms as $term){ ?>
<li class="filter" data-filter=".category<?php echo $term->term_id; ?>"><?php echo $term->name; ?></li>
<?php } ?>
</ul>
<ul class="list_right_col_item_programs img_width">
<?php
$args = array(
'post_type' => 'programs',
);
$query = new WP_Query( $args );
if ($query->have_posts()) {
while ( $query->have_posts() ) : $query->the_post(); ?>
<li class="mix category<?php $terms = get_the_terms( $post->ID, 'genretax' );
if( $terms ){
$term = array_shift( $terms );
echo $term->term_id;
} ?>">
<a href="<?php the_permalink(); ?>" class="img_col_item_programs">
<?php echo get_the_post_thumbnail(get_the_ID()); ?>
</a>
<a href="<?php the_permalink(); ?>" class="link_col_item_programs"><?php the_title(); ?></a>
</li>
<?php endwhile;
}
wp_reset_postdata(); ?>
</ul>
Answer the question
In order to leave comments, you need to log in
Most likely, if the post has several categories, then they all need to be displayed in the tag<li>
$classes = array();
$classes[] = 'mix';
if ( $terms = get_the_terms( get_the_ID(), 'genretax' ) ) {
foreach ( $terms as $key => $term ) {
$classes[] = 'category' . $term->term_id;
}
}
echo '<li class="' . implode( ' ', $classes ) . '">';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question