Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created June 7, 2012 05:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramseyp/2886744 to your computer and use it in GitHub Desktop.
Save ramseyp/2886744 to your computer and use it in GitHub Desktop.
Exclude a post format from the main query in WordPRess
<?php
/**
* Add a taxonomy query to pre_get_posts to remove Quote post formats from the main query
*
* @author Pat Ramsey
* @link http://slash25.com
*
* @param array tax_query $args
* @return modified $query
*/
function exclude_post_format( $query ) {
// conditionals to affect only the main query on the blog page ( Settings -> Reading )
if ( $query->is_home() && $query->is_main_query() ) {
// tax_query takes a double array
$args = array ( array (
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-quote',
'operator' => 'NOT IN'
));
$query->set( 'tax_query', $args );
}
}
add_action( 'pre_get_posts', 'exclude_post_format' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment