我使用以下代碼(沒有 post__not_in 部分)在單個產品視圖中使用 wordpress woocommerce 查詢評分最高的產品。我需要從查詢中排除當前帖子和精選帖子。知道如何同時排除它們嗎?
$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 )
));
uj5u.com熱心網友回復:
您是否嘗試過合并陣列?不確定您是否可以在同一查詢中使用 post__not_in 兩次。
"post__not_in" => array_merge(array( $post->ID ), wc_get_featured_product_ids())
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/405231.html
標籤:
