How to exclude / hide posts of a category (or multiple categories) from displaying in the blog homepage?


Suppose you have a blog on WordPress setup and customization, and you want to hide “Books Review” and “Hosting Review” from blog homepage(is_home). Because you want to place them in the navigation menu.

So here is an easy tutorial at your service.

  • You have to find the category id for each categories. You can find them from Dashboard > Posts > Categories, click on Edit and take a note of the number beside tag_ID=. Repeat the step if you want to exclude multiple categories.
  • Now open functions.php file from WordPress theme folder. If you are using our basic WordPress child theme, you may have to create a file called functions.php.
  • Paste the following code in the file.
1
2
3
4
5
6
function exclude_category( $query ) {
    if ( $query->is_home ) {
        $query->set( 'cat', '-15,-48' );
    }
}
add_action( 'pre_get_posts', 'exclude_category' );
  • Number represents the category id. Suppose your Book Review category id is 15 and Hosting Review category id is 48. If you have multiple category, add a minus (-) before your category id and add them with a comma (,) separators as we did.
  • Now save the file and upload to your theme folder.
  • Refresh your homepage. I believe you have successfully excluded all posts of a category (or multiple categories) from your homepage.

Request for this article came from one of our readers via Ask for Help section. If you want some help, why don’t you leave a comment or ask for professional WordPress help and our team will contact you shortly.

Regards,
Jinnat Ul Hasan

By | On Wednesday, August 24th, 2011 | Under How To's | No Comments ┬╗


DO YOU NEED OUR HELP?

Contact our experts, most of the time we assist our readers free of charge.

Those who found this page were searching for:

  • twenty eleven query post category
  • filter wordpress by multiple categories#q=wordpress display post by multiple categories
  • wordpress rss how to exclude categories
  • wordpress exclude post with multiple categories
  • wordpress exclure une cat├ęgorie twenty eleven
  • hide post of specific category from post page ...
  • wordpress exclude category twentyeleven
  • hide posts by category wordpress
  • post in multiple categories hide
  • exclude categories from your homepage post

Previous post:

Next post: