I made one blog post page and 2 second page I made for uncategorized category page using this file category-uncategorized.php and now I want to remove this all uncategorized category from blog page.
and here is a code
<?php if(have_posts()) :
while (have_posts()) :
the_post();
get_template_part('content', get_post_format());
endwhile;?>
<?php echo bootstrap_pagination($query) ?>
<?php else :
echo '<p>No Content Found</p>';
endif;?>
I made one blog post page and 2 second page I made for uncategorized category page using this file category-uncategorized.php and now I want to remove this all uncategorized category from blog page.
and here is a code
<?php if(have_posts()) :
while (have_posts()) :
the_post();
get_template_part('content', get_post_format());
endwhile;?>
<?php echo bootstrap_pagination($query) ?>
<?php else :
echo '<p>No Content Found</p>';
endif;?>
Share
Improve this question
edited Jun 26, 2019 at 11:25
Rup
4,4004 gold badges29 silver badges29 bronze badges
asked Jun 26, 2019 at 9:48
Vishal KunwerVishal Kunwer
1
1
|
1 Answer
Reset to default 0Please try code given below:
function blog_exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-1' );
}
}
add_action( 'pre_get_posts', 'blog_exclude_category' );
Add this in your functions.php
pre_get_posts
to change the query on whichever URL you are talking about, to exclude that category. – WebElaine Commented Jun 26, 2019 at 13:12