• Is it possible to publish posts with a certain category but not show up on the static “home” page (where all posts show up).

    We are going to create a news letter and use posts in the news letter but before the news letter has been sent out I do not want the posts to show up on the static “home” page.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You could do something like this:

    function exclude_category($query) {
    	if ( $query->is_home() ) {
    		$query->set('cat', '-46');
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    where 46 is the ID of the category you want to exclude.

    Thread Starter gabby_wordpress

    (@gabby_wordpress)

    Hi OakwoodGates,

    I will give it a try and see if that works.

    Thanks.

    Thread Starter gabby_wordpress

    (@gabby_wordpress)

    Hi OakwoodGates,

    I cannot see any id for the categories. Where can I find out what id the specific category has?

    If you are in the wp-admin->Posts->Categories, and click on the category, then take a look at the url in the browser. Somewhere in that url, you should see something like ID=46 (or whatever).

    Does that make sense?

    Thread Starter gabby_wordpress

    (@gabby_wordpress)

    That does make sense. I am going to check it out.

    I use this code to exclude my categories from various places, similar to what oakwoodgates posted:

    function remove_my_categories( $wp_query ) {
      // 61 = Daily Tweets, 74 = Testing
      $remove_cat = '-61,-74';
    
      // remove from archives (except category archives), feeds, search, and home page, but not admin areas
      if( (is_home() || is_feed() || is_search() || ( is_archive() && !is_category() )) && !is_admin()) {
        set_query_var('cat', $remove_cat);
        //which is merely the more elegant way to write:
        //$wp_query->set('cat', '-' . $remove_cat);
      }
    }
    
    add_action('pre_get_posts', 'remove_my_categories' );

    Whatever works. ??

    Thread Starter gabby_wordpress

    (@gabby_wordpress)

    Hi MarkRH,

    Thanks for your code.

    I will test your code as well.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Posts with a certain category not visible on static’ is closed to new replies.