I'm working on a site that's running Domain Theme Mapper (http://codecanyon.net/item/domain-and-theme-mapper) with WooCommerce to present two sites with two different child themes... that share a database with product details. The client wants some product/posts to show on both sites and some to show up on only one or the other.

We've added this code to functions.php in each theme to show products based on the theme chosen:

add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;

    if ( ! is_admin() && is_shop() ) {

        $q->set( 'tax_query', array(array(
            'taxonomy' => 'site',
            'field' => 'slug',
            'terms' => array( 'site1' ),/*or site2*/
            'operator' => 'IN'


    remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );


This works great for the WooCommerce shop page, but doesn't effect other queries. Is there a way to generalize this to effect ALL queries (posts, products, pages) made by WordPress when the appropriate child theme is selected?

I imagine that I could modify the WordPress main queries in some way, but I don't know my way around them that well. The fix would have to be within the child theme to work... but if the custom taxonomy is unwieldy, it could be done by checking domain.

Thank you in advance for any thoughts!


From the Codex for pre_get_posts:

pre_get_posts cannot be used to alter the query for Page requests (page templates) because 'is_page', 'is_singular', 'pagename' and other properties (depending if pretty permalinks are used) are already set by the parse_query() method. See: Query Overview. The recommended way to alter the main query for page requests is to use new WP_Query in the page template itself.

So, I'd suggest seeing if new WP_Query ( http://codex.wordpress.org/Class_Reference/WP_Query ) could help you here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.