[英]Combine two queries, one query after another
I have two woocommerce queries, I want to display on the same page both queries, first the query with image and after the query without image, how do I merge them, so they will not mix?我有两个 woocommerce 查询,我想在同一页面上显示两个查询,首先是带有图像的查询,然后是没有图像的查询,如何合并它们,这样它们就不会混合?
$argWithImage = array(
'post_type' => 'product',
'posts_per_page' => -1,
'product_cat' => $queried_object->slug,
'meta_key' => '_thumbnail_id',
);
$argWithoutImage = array(
'post_type' => 'product',
'posts_per_page' => -1,
'product_cat' => $queried_object->slug,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'value' => '?',
'compare' => 'NOT EXISTS'
)
),
);
$merged_query_args = array_merge( $argWithImage, $argWithoutImage );
$query = new WP_Query( $merged_query_args );
You need to execute each query separately in the same template file.您需要在同一个模板文件中分别执行每个查询。 You can't merge them in one query because their data is conflicting, do it like below:
您不能将它们合并到一个查询中,因为它们的数据是冲突的,如下所示:
$productsWithImage = new WP_Query( $argWithImage );
// The Loop
while ( $productsWithImage->have_posts() ) : $productsWithImage->the_post();
?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br
/><?php
endwhile;
// Reset Post Data
wp_reset_postdata();
$productsWithoutImage = new WP_Query( $argWithoutImage );
// The Loop
while ( $productsWithoutImage->have_posts() ) : $productsWithoutImage->the_post();
?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br
/><?php
endwhile;
// Reset Post Data
wp_reset_postdata();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.