wp query – Removing ORDER_BY in a WP_QUERY for deterministic result set
Question
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_product dg ON dg.post_id = wp_posts.ID
AND ( dg.location IN ('XV', 'QV', 'DH') )
AND (0 OR (dg.srp = 1) OR (dg.SoldDate > (now() - interval 30 DAY)
AND dg.isPremium = 0 AND dg.SoldDate != '0000-00-00 00:00:00'
AND dg.SoldDate IS NOT NULL AND price > 0 AND NoImage = 0))
AND ( dg.deleted IS NULL OR dg.deleted <> 1 )
WHERE 1=1 AND ( wp_postmeta.meta_key = '_product_info_new' )
AND wp_posts.post_type="product"
AND (wp_posts.post_status="publish")
GROUP BY wp_posts.ID
ORDER BY dg.SoldDate IS NULL, dg.SoldDate ASC, dg.isPremium DESC LIMIT 0, 30
I have this query and I am wondering if GROUP BY wp_posts.ID can be removed? I am thinking it’s there to remove duplicates, but is there another way to remove duplicates? Because the GROUP BY wp_posts.ID causes the values returned to be non-deterministic, meaning that the query gives a different result every time. Is there a way to fix this? In my understanding a post can have several postmeta associated with it.
0
10 months
2022-04-10T08:21:37-05:00
2022-04-10T08:21:37-05:00 0 Answers
0 views
0
Leave an answer