admin管理员组文章数量:1336660
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?
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?
Share Improve this question edited May 19, 2020 at 16:41 Vito Santimone asked May 19, 2020 at 16:21 Vito SantimoneVito Santimone 12 bronze badges1 Answer
Reset to default 0I haven't tested you method yet. However I had bookmarked few closely related topics (also for me to try & error) as below:
- how to override woocommerce specific loop or archive-product.php
- WP_Query | Help me create a search term with an 'OR' relation?
- Find all product that contain terms with %keywords% in WP_Query
- Get posts from sites in Multisite?
- restore_current_blog() vs switch_to_blog()
- How would I use pre_get_posts to query another site for posts in my multisite network?
Hope Help!
本文标签: Woocommerce Multisite Search Mod to archivephp but no pagination
版权声明:本文标题:Woocommerce Multisite Search Mod to archive.php but no pagination 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742417857a2471065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论