SOLVED: Query editor (PHP) in Query Loop output incorrect results

Browser: Chrome 110
OS: Windows

After updating to 1.9.6 and 1.9.6.1, the Query editor (PHP) in the query loop does not work (the output results are not in the right quantity and sorted correctly). I tested in 1.9.2-1.9.5 and they all work.

Issue:
I am using the following PHP to display up-sells products on the woocommerce cart page.

$up_sells = array();
$cart_ids = array(); // Store IDs of products in the cart


foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $product = $cart_item['data'];
    if ($product && $product->exists()) {
        $cart_ids[] = $product->get_id(); // Save each product ID in the cart
        if ($product->get_upsell_ids()) {
            $up_sells = array_merge($up_sells, $product->get_upsell_ids());
        }
    }
}


// Use array_diff to remove products from $up_sells that are already in the cart
$up_sells = array_diff($up_sells, $cart_ids);
$up_sells = array_unique($up_sells);


      
return [
         'post_type' => 'product',
         'posts_per_page' => 3,
         'orderby' => 'menu_order title',
         'order' => 'ASC',
         'post__in' => $up_sells,
       ];

The correct display result in 1.9.2-1.9.5 is:

The wrong result In 1.9.6 and 1.9.6.1 is:

Hi Ying,
Thanks so much for your report, and sorry for the late reply!

I can confirm an issue with the query editor and added it to our bug tracker.

Best regards,
timmse

Dear @Ying ,

Bricks Query logic enhanced in 1.9.6 and above.
QueryEditor will also run bricks/posts/query_vars hook since 1.9.6
Hence, your query will be affected by Bricks’ WooCommerce logic.
To avoid this, kindly add 'disable_query_merge' => true parameter as well.

Example:

return [
         'post_type' => 'product',
         'posts_per_page' => 3,
         'orderby' => 'menu_order title',
         'order' => 'ASC',
         'post__in' => $up_sells,
         'disable_query_merge' => true,
 ];

Can you try?

Regards,
Jenn

Hi Jenn,

I tried adding 'disable_query_merge' => true, and it still still doesn’t output the correct result.

Hi @Ying ,

My bad… typo

disable_query_merge

No past tense on disable :stuck_out_tongue:

Regards,
Jenn

Thank you! It’s working now.

1 Like