Im正在修改存档。php在我的woocommerce主题中进行多站点全局搜索。我添加了以下代码:
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;
}
?>
似乎有效,但有一些问题!例如如果我搜索一个在站点1和站点2有很多结果的术语,那么它可以很好地进行分页。如果我只在站点2中搜索一个有数千个结果的词,我只能看到36个没有分页的结果。有人有什么建议吗?