Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active March 28, 2019 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/1238202 to your computer and use it in GitHub Desktop.
Save billerickson/1238202 to your computer and use it in GitHub Desktop.
Exclude Category from Blog
<?php
add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
/**
* Exclude Category from Blog
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function be_exclude_category_from_blog( $query ) {
if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
$query->set( 'cat', '-4' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment