Im modifyng archive.php in my woocommerce theme to have multisite global search. I added this code:

    if ( is_search() ) {

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

$query_args = array(
            'posts_per_page' => 48,
            'post_status'    => 'publish',
            'post_type'      => 'product',
            'orderby'        => 'ASC',
            'no_found_rows'  => 1,
            //'paged'          => -1,
$query_args['product_cat'] = strip_tags( $_REQUEST['product_cat'] );  
$query_args['meta_query'][] = array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => 'NOT IN' );

do_action( 'woocommerce_before_shop_loop' );

$searchfor = get_search_query();
$blogs = get_sites();
foreach ( $blogs as $blog ):
$search_query = new WP_Query($query_args);

while ( $search_query->have_posts() ) {
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );


  do_action( 'woocommerce_after_shop_loop' );
  do_action( 'woocommerce_after_main_content' );
  do_action( 'woocommerce_sidebar' );
  get_footer( 'shop' ); 

Seems to work, but with some problem! For example. iIf i search a terms that has many results in site 1 and site 2 it works perfectly with pagination. If i search a term that has thousands of result in site 2 only, i can see only 36 results without pagination. Someone has any suggestion?

1 Answer 1


I haven't tested you method yet. However I had bookmarked few closely related topics (also for me to try & error) as below:

  1. how to override woocommerce specific loop or archive-product.php
  2. WP_Query | Help me create a search term with an 'OR' relation?
  3. Find all product that contain terms with %keywords% in WP_Query
  4. Get posts from sites in Multisite?
  5. restore_current_blog() vs switch_to_blog()
  6. How would I use pre_get_posts to query another site for posts in my multisite network?

Hope Help!

  • Sorry but no one of this is a good solution. The problem is more complex. The site does two search cycles, 1 on site 1 and the other on site 2. The problem is that the "pagination" is asked when the site does the first search cycle and if it finds results lower than the requested it does not include it in the template. Here then that compared to 3 results on site 1 and maybe 1000 on site 2 shows only the first 36. What should be done is to tell the site to do the paging if the search is greater than 36 results, which for now is not I managed to do. Do you have any idea about it? Thanks Commented May 20, 2020 at 14:51
  • Hi @VitoSantimone you can refer to Network Posts with Pagination Commented May 21, 2020 at 5:05
  • Are 2 different things. This refer to a plugin with pagenavi....not a solution. Commented May 21, 2020 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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