第一次查询,选择找到的记录
$old_args = array(
\'post_type\' => \'product\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'_sale_price_dates_to\',
\'value\' => $timenow,
\'compare\' => \'>=\',
\'type\' => \'numeric\'
) ,
array(
\'key\' => \'_sale_price_dates_to\',
\'value\' => \'\',
\'compare\' => \'!=\'
) ,
array(
\'key\' => \'wccaf_location_zipcode\',
\'value\' => array(
\'78774\',
\'73344\'
) ,
\'compare\' => \'IN\'
)
) ,
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'id\',
\'terms\' => $cat_id
)
)
);
$loop1 = new WP_Query($old_args);
$posts = array();
if ($loop1->have_posts()):
while ($loop1->have_posts()):
$loop1->the_post();
$posts[] = $loop1->post->ID; // Storing the post_ID\'s result in array.
endwhile;
else:
echo "No product Found";
endif; //loop close
第二次查询,选择未找到的记录
$new_args = array(
\'post_type\' => \'product\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'_sale_price_dates_to\',
\'value\' => $timenow,
\'compare\' => \'>=\',
\'type\' => \'numeric\'
) ,
array(
\'key\' => \'_sale_price_dates_to\',
\'value\' => \'\',
\'compare\' => \'!=\'
) ,
array(
\'key\' => \'wccaf_location_zipcode\',
\'value\' => array(
\'78774\',
\'73344\'
) ,
\'compare\' => \'NOT IN\'
)
) ,
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'id\',
\'terms\' => $cat_id
)
)
);
$loop2 = new WP_Query($new_args);
$result_not_found_array = array();
if ($loop2->have_posts()):
while ($loop2->have_posts()):
$loop2->the_post();
$posts[] = $loop2->post->ID; // Storing the post_ID\'s result in array.
endwhile;
else:
echo "No product Found";
endif; //loop close
将结果合并到第三个数组中
$post_ids = array_merge($result_found_array, $result_not_found_array);
$loop = new WP_Query(array(
\'post_type\' => \'product\',
\'post__in\' => $posts,
\'paged\' => $paged,
\'posts_per_page\' => 5
));
现在我想根据合并数组索引得到结果。我想显示首先找到的结果和最后未找到的结果。例如:-合并数组为
101,104,103,106
. 就像那样,我想要我的结果。