Created
October 4, 2012 13:19
-
-
Save kovshenin/3833482 to your computer and use it in GitHub Desktop.
Remove posts from a certain category
This file contains hidden or 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 | |
/** | |
* Plugin Name: Hide posts from category on home page | |
*/ | |
add_action( 'pre_get_posts', 'my_pre_get_posts' ); | |
function my_pre_get_posts( $query ) { | |
// Category IDs to exclude | |
$exclude_categories = array( 1, 2, 3 ); | |
if ( $query->is_home() ) | |
$query->set( 'category__not_in', $exclude_categories ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
...and when people want to display a portion of their blog posts on their static home page, they can expand the
$query->is_home()
condition like this:It seems that many WP developers use
query_posts()
which, in fact, causes more problems than it solves.Sweet.