I'm having trouble recreating a query from straight mySQL to $wpdb compatible.

SELECT meta_value
FROM `wp_postmeta`
WHERE meta_key = 'review_rating'
AND meta_value = 5
AND post_id IN (118,117,116,115,114,113,112,110,109,161)

When testing in Sequel Pro app it returns the correct number of posts that match the meta_value from the post_ids but when used in Wordpress it only returns "1"

Not sure what I'm doing wrong on including an integer/number into the SQL query. Any help would be appreciated.

  • Your code, or it is as if you haven't asked at all.... – Mark Kaplun Feb 5 '16 at 6:20
  • 1
    Why use custom SQL where you loose all filters and caches. Use WP_Query which will build a more reliable SQL query – Pieter Goosen Feb 5 '16 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.