从 WP_Query 中排除当前产品和特色产品
Exclude current product and featured products from WP_Query
我使用以下代码(没有 post__not_in 部分)在单个产品视图中使用 wordpress woocommerce 查询评分最高的产品。我需要从查询中排除当前的 post 和 feautred post。知道如何同时排除它们吗?
$the_query = new WP_Query( array(
// Order by best rated products
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '-1',
'orderby' => 'meta_value_num',
'order' => 'desc',
'meta_key' => '_wc_average_rating',
'post__not_in' => wc_get_featured_product_ids(),
'post__not_in' => array( $post->ID )
));
你试过合并数组吗?不确定您是否可以在同一查询中两次使用 post__not_in。
"post__not_in" => array_merge(array( $post->ID ), wc_get_featured_product_ids())
我使用以下代码(没有 post__not_in 部分)在单个产品视图中使用 wordpress woocommerce 查询评分最高的产品。我需要从查询中排除当前的 post 和 feautred post。知道如何同时排除它们吗?
$the_query = new WP_Query( array(
// Order by best rated products
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '-1',
'orderby' => 'meta_value_num',
'order' => 'desc',
'meta_key' => '_wc_average_rating',
'post__not_in' => wc_get_featured_product_ids(),
'post__not_in' => array( $post->ID )
));
你试过合并数组吗?不确定您是否可以在同一查询中两次使用 post__not_in。
"post__not_in" => array_merge(array( $post->ID ), wc_get_featured_product_ids())