Exclude post format from main query
-
I’m wanting to use
pre_get_posts
to exclude some posts from my main query — I want to include only ‘standard’ post formats in the main portion of the blog, and exclude ‘video’ and ‘aside’ post formats.The query I’ve got in place now sort of accomplishes what I want:
<?php $args = array( 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-video','post-format-aside'), 'operator' => 'NOT IN' ) ) ); $main_blog = new WP_Query(); // Main blog query $main_blog->query( $args ); ?> <?php if ( $main_blog->have_posts() ) : while ( $main_blog->have_posts() ) : $main_blog->the_post(); //Main blog loop ?>
But this isn’t really the right way to change the main query, right? For one thing, it breaks the “older posts” link at the bottom of the home page.
Can anyone help me with the code for using
pre_get_posts
to accomplish this. I guess I need to usetax_query
? There doesn’t seem to be any way to directly reference “post formats.” Thank you!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Exclude post format from main query’ is closed to new replies.