(Queries are definitively an infinite source of misunderstanding...)
I try to display two types of informations in a tax archive (taxonomy-artiste.php
) :
- The content of a page from a custom post (bio)
- And after, a list of post from another custom post (works)
If I understood well, it could be interesting to use pre_get_post to change the main query.
So, I set that in my function.php
.
//Include all my CPT but the bio function lm_exclude_bio( $query ) { if( is_tax('artiste') && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'cpt#1', 'cpt#2' )); return $query; } } add_filter( 'pre_get_posts', 'lm_exclude_bio' );
Ok, it works.
But, when I add a new query in this archive, it doesn't display the post I excepted...
$args = array( 'post_type' => 'bio', 'posts_per_page' => 1 ); // My second query for CPT 'bio' $bio_query = new WP_Query( $args ); // The Loop if ( $bio_query->have_posts() ) { while ( $the_query->have_posts() ) { $bio_query->the_post(); // please, my custom post 'bio' !... } /* Restore original Post Data */ wp_reset_postdata(); } else { // no posts found ?>
Is it impossible( stupid ?) to set two queries with opposite arguments ? Thanks for any help !