category omission from front page causes admin search "anomaly"

Community Forums Forums General Discussion category omission from front page causes admin search "anomaly"

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  Summer 9 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #71938

    SmockLady
    Participant
    Post count: 1

    So here’s what’s going on and this is WELL beyond me and my minor bits of knowledge…
    I am using the Beautiful Pro (customized) theme, which I don’t think matters much here but it might.
    Everything (mostly) is set the way I want it; I am trying to exclude a particular category from my home page. I have been able to do this successfully with a strange twist – it also excludes it from my admin posts list and I can’t search for it either.

    Here’s the code I am using:

    /**Customizing Home page feed **/
    function exclude_category( $query ) {
        if ( $query->is_page() && $query->is_main_query() ) {
            $query->set( 'cat', '-223,-288, -22' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    When I use it this way, the category posts show on my home page and are searchable in my admin posts.

    When I comment out a portion of it and use it this way:

    /**Customizing Home page feed **/
    function exclude_category( $query ) {
        if ( /*$query->is_page() &&*/ $query->is_main_query() ) {
            $query->set( 'cat', '-223,-288, -22' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    It removes the category posts from my home page as I desire, but they also get removed from my post list in the admin panel. What do I need to change?

    http://thefloodedfishbowl.com
    #71986

    Summer
    Participant
    Post count: 1071

    Wouldn’t you want to use is_home and is_front_page instead?


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.