Support » Fixing WordPress » Exclude categories from main page question

  • Hello, I am using the following function to exclude posts(categories) from the main page of my blog.

    function my_exclude_category( $query ) {
      if ( $query->is_home ) {
    		$query->set( 'cat', '-3');
    	return $query;
    add_filter( 'pre_get_posts', 'my_exclude_category' );

    It works great, but I want it to work only if I have selected 1 category(when creating the post) so:

    If the post is on Videos category(id = cat3) I want it to be hidden, but if I check both Video category and General when making the post, it should be visible.

    Is that possible?

Viewing 1 replies (of 1 total)
  • Not sure if I described that correctly, here’s what I am trying to do:

    if ( $query->in_category(-3) && in_category(-7) ){
         //display the posts that are included in these two categories(3,7)
    //else if they are in any of each of these categories(not both)hide them
    else { $query->set( 'cat', '-3 -7');}
Viewing 1 replies (of 1 total)
  • The topic ‘Exclude categories from main page question’ is closed to new replies.