SELECT
CASE
WHEN (pm.meta_key = 'pricing_promo' && LENGTH( pm.meta_value ) > 0)
THEN LENGTH(FORMAT( REPLACE ( pm.meta_value, ',', '' ), 2 ))
WHEN (pm.meta_key = 'pricing' && LENGTH( pm.meta_value ) > 0)
THEN LENGTH(FORMAT( REPLACE ( pm.meta_value, ',', '' ), 2 ))
ELSE 'Z'
END as pricelength,
CASE
WHEN pm.meta_key = 'pricing_promo' AND pm.meta_value <> ""
THEN FORMAT( REPLACE ( pm.meta_value, ',', '' ), 2 )
WHEN pm.meta_key = 'pricing'
THEN FORMAT( REPLACE ( pm.meta_value, ',', '' ), 2 )
ELSE FORMAT('0',2) END AS price
, a.*
FROM wp__posts a INNER JOIN wp__term_relationships e ON a.ID = e.object_id
INNER JOIN wp__term_taxonomy c ON c.term_taxonomy_id = e.term_taxonomy_id
INNER JOIN wp__terms d ON c.term_id = d.term_id
INNER JOIN wp__postmeta pm ON a.ID = pm.post_id
WHERE e.object_id = a.ID AND d.slug = 'product-category'
AND a.post_status='publish'
AND a.post_type = 'product'
AND pm.meta_key = (IF (pm.meta_key = 'pricing_promo' ,'pricing_promo','pricing'))
GROUP BY a.id
Order By pricelength asc, price asc, a.post_title asc LIMIT 28 offset 0
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.