I'm new at Wordpress development and I was wondering (and trying to solve this) for a long time, so maybe you can help me.
My WP use a custom post type named Products. And there is a custom taxonomy with a lot of terms that describe that products.
i.e:
- Products (custom post type)
- ----Product line (custom taxonomy)
- -----------Cardline (term in custom taxonomy)
- -----------Boneline (term in custom taxonomy)
- -----------Odoline (term in custom taxonomy)
- -----------Gineline (term in custom taxonomy)
So, I was able to list all the terms of my custom taxonomy, and to do a while loop to list all the posts inside each term.
However, I was looking to a while loop to list the posts that are related to only one of my custom taxonomy's terms. For example: I want to list only the "international books".
I've tried a lot of solutions, but I still can't get it. Do you have any idea that may help me? I'm working on this. But I can't get anything.
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'line',
'field' => 'slug',
'terms' => array( 'cardline' )
),
),
'post_type' => 'prod'
);
$query = new WP_Query( $args );
if ( have_posts() ) {
$term = $query->queried_object;
while ( have_posts() ) : the_post();
//Output my posts
the_title();
the_content();
endwhile;
}
//RESET YOUR QUERY VARS
wp_reset_query();
?>
Thanks!
$query
, but your loop does not output the contents of that query object. Refer to WP_Query: Multiple Loops example for the correct syntax.