Skip to content

Instantly share code, notes, and snippets.

@davemac
Created December 10, 2011 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davemac/1456987 to your computer and use it in GitHub Desktop.
Save davemac/1456987 to your computer and use it in GitHub Desktop.
Function to exclude a category(s) from the main loop (pre WP 3.3) in certain categories
add_action( 'pre_get_posts', 'dm_exclude_category_from_category' );
function dm_exclude_category_from_category( $query ) {
global $wp_the_query;
if( $wp_the_query === $query && $query->is_category( array (4,5,6,7) ) ) {
$query->set( 'cat', '-25' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment