mikelittle

Exclude Categories from blog list

Apr 17th, 2013
210
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'pre_get_posts', 'zed1_exclude_front_page_cats' );
  2. function zed1_exclude_front_page_cats( $query ) {
  3.  
  4.     // if this is not the main query on the page, do nothing
  5.     if ( !$query->is_main_query() )
  6.         return;
  7.  
  8.     // if this is meant to show cat-a, do nothing
  9.     if ( $query->is_category( 'cat-a' ) )
  10.         return;
  11.  
  12.     // if this is meant to show cat-b, do nothing
  13.     if ( $query->is_category( 'cat-b' ) )
  14.         return;
  15.  
  16.     // otherwise, exclude cat-a and cat-b
  17.     $tax_query = array (
  18.                         array (
  19.                                'taxonomy' => 'category',
  20.                                'field' => 'slug',
  21.                                'terms' => array( 'cat-a', 'cat-b' ),
  22.                                'operator' => 'NOT IN'
  23.                               )
  24.                        );
  25.     $query->set( 'tax_query', $tax_query );
  26. } // end zed1_exclude_front_page_cats
RAW Paste Data