[Resolved] Need to display posts from certain categories at Home, keeping navigation AS IS

Home Forums Support [Resolved] Need to display posts from certain categories at Home, keeping navigation AS IS

Home Forums Support Need to display posts from certain categories at Home, keeping navigation AS IS

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

    Hi,

    I see this queries has been posted before a lot of time here. I visited docs as well. My requirement is similar what discussed already.

    I need to display just certain categories posts at Home archives.

    So I tried this way

    add_filter( 'pre_get_posts', 'news_category_home' );
    
    function news_category_home( $query ) {
    if ( $query->is_home ) {
    $query->set( 'cat', '490, 3286, 36, 3304, 26, 7' );
    }
    return $query;
    }

    Exact issue: The problem is it hide my set menus. I tried putting custom link in a test-menu. That also doesn’t appear at all. Means, no menu appear once above code is placed. Only thing I see is header search box in navigation place.
    Sadly, happens with Twenty Twenty theme as well.

    Is there any nice way to get around it?

    Thanks

    #1385675
    David
    Staff
    Customer Support

    Hi there,

    try this:

    add_action( 'pre_get_posts', function( $query ) {
        if ( $query->is_main_query() && is_home() ) {
            $query->set( 'cat', '490, 3286, 36, 3304, 26, 7' );
        }
    } );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.