Displaying Only Certain Tags in Loop

  • Create a must-use plugin.
  • Put it in <docroot>/wp-content/mu-plugins/selective-posts.php
  • Following should be the code in selective-posts.php to filter specific posts.

    function golfclubs_tag( $query ) {
        if ( $_SERVER['HTTP_HOST'] === 'www.golfclubreviewdomain.com' ) {
            $query->set( 'tag', 'golfclubs' );
        }
    }
    add_action( 'pre_get_posts', 'golfclubs_tag' );
    

This way it would filter all the queries across the site for specific domain and it would filter the posts with specific tag.

If you want to add another tag in the query, you can edit the above code as follows:

    function golfclubs_tag( $query ) {
        if ( $_SERVER['HTTP_HOST'] === 'www.golfclubreviewdomain.com' ) {
            $query->set( 'tag', 'golfclubs,general' );
        }
    }
    add_action( 'pre_get_posts', 'golfclubs_tag' );