Skip to content

Instantly share code, notes, and snippets.

@megantaylor
Last active August 29, 2015 14:05
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 megantaylor/fb86fb9cfc026208b928 to your computer and use it in GitHub Desktop.
Save megantaylor/fb86fb9cfc026208b928 to your computer and use it in GitHub Desktop.
exclude categories from WP home page
in functions.php file
<?php
add_filter( 'pre_get_posts', function ( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$example_term = get_term_by( 'name', 'featured', 'category' );
$example_term_2 = get_term_by( 'name', 'Featured Post', 'category' );
$example_term_3 = get_term_by( 'name', '1,000 Stories', 'category' );
$example_term_4 = get_term_by( 'name', '1,000 Stories Spotlight', 'category' );
$query->set( 'category__not_in', $example_term->term_id, $example_term_2->term_id, $example_term_3->term_id, $example_term_4->term_id );
}
});
?>
in index.php file
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
x_get_view( 'ethos', 'content', get_post_format() );
}
}
?>
@megantaylor
Copy link
Author

Thanks! Fixed that, but posts are still not being excluded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment