Set homepage to only display posts from one tag

I’d like my homepage to only display posts from a single tag. Is this possible? If yes, please advise.

For instance,

www.mysite.com/tag/sometag

will only display posts with the sometag tag, but how do I get www.mysite.com to automatically display only the posts seen on

www.mysite.com/tag/sometag
page?

3 Answers
3

You should use pre_get_posts to alter the main query on the home page.

With the proper conditional tags and parameters (check WP_Query for available parameters) you can achieve what you need

You can do the following to just display posts from a given tag on your homepage

add_action( 'pre_get_posts', function ( $query ) {
    if ( !is_admin() && $query->is_home() && $query->is_main_query() ) {
        $query->set( 'tag', 'SLUG_OF_TAG' );
    }
});

Leave a Comment