Skip to content

Instantly share code, notes, and snippets.

@unix7
Created September 12, 2012 14:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unix7/3707162 to your computer and use it in GitHub Desktop.
Save unix7/3707162 to your computer and use it in GitHub Desktop.
Exclude Certain Post Format from Blog Loop
//Source: http://www.billerickson.net/customize-the-wordpress-query/#example-category
<?php
/**
* Exclude Post Formats from Blog
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function be_exclude_post_formats_from_blog( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$tax_query = array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-aside', 'post-format-quote' ),
'operator' => 'NOT IN',
);
$query->set( 'tax_query', $tax_query );
}
}
add_action( 'pre_get_posts', 'be_exclude_post_formats_from_blog' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment