Created
June 7, 2012 05:27
-
-
Save ramseyp/2886744 to your computer and use it in GitHub Desktop.
Exclude a post format from the main query in WordPRess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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