Last active
August 29, 2015 14:05
-
-
Save megantaylor/fb86fb9cfc026208b928 to your computer and use it in GitHub Desktop.
exclude categories from WP home page
This file contains 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
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() ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Fixed that, but posts are still not being excluded.