Answer the question
In order to leave comments, you need to log in
How to display different types of posts for the created taxonomy depending on the query?
Hello! I have a wordpress site with a custom theme.
There are 3 arbitrary types of posts - car brands ( bmw, mazda, ford ) and a taxonomy of classification by years created for them: the base years and its children 2010,2011,2012 , etc.
Created a taxonomy-years.php template where I display a list of cars by years
<?php $cat = get_term_by('name', single_cat_title('',false), 'years'); $catSlug = $cat->slug;
$mypost = array(
'post_type' => 'bmw',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'years',
'field' => 'slug',
'terms' => $catSlug
),
),
);
$loop = new WP_Query( $mypost );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<div>Характеристики авто</div>
<?php endwhile; wp_reset_postdata(); ?>
Answer the question
In order to leave comments, you need to log in
1. The post_type parameter in WP_Query can take an array, not just one bmw, string|array there.
2. The same taxonomy can be registered for a set of custom post types, there is also a string|array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question