Site logo

Archived topic

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

1 reply · Started by Gulshan on August 3, 2020

Viewing posts 1–2 of 2

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

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' );
    }
} );
This archived topic is closed to new replies.