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' );
woocommerce_product_loop_start();
$searchfor = get_search_query();
$query_string=esc_attr($query_string);
$blogs = get_sites();
foreach ( $blogs as $blog ):
switch_to_blog($blog->blog_id);
$search_query = new WP_Query($query_args);
while ( $search_query->have_posts() ) {
$search_query->the_post();
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
wp_reset_postdata();
restore_current_blog();
endforeach;
woocommerce_product_loop_end();
do_action( 'woocommerce_after_shop_loop' );
do_action( 'woocommerce_after_main_content' );
do_action( 'woocommerce_sidebar' );
get_footer( 'shop' );
exit;
}
?>
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?