0

I have this query and its not returning anything even though I have specific user meta for 1 user.

SELECT * FROM `wp_usermeta` 
WHERE meta_key= 'referrer' AND 
meta_value LIKE '270' AND 
meta_key= 'view_type' AND 
meta_value LIKE 'invoice'

What is wrong with this query?

  • A single meta key can't have two different names and values at the same time, I think you want some ORs in there. – Milo Dec 6 '16 at 3:58
  • You need one join per meta key - out of interest, why are you using SQL and not WP_Query? – TheDeadMedic Dec 6 '16 at 10:16
  • Yes I created a Join query and it works as to why not use wp_query its because when you do complex meta queries its just to slow using wp_query. – Nelson101 Dec 22 '16 at 7:42
1

It's probably because you must use % sign for "like" so it would be:

SELECT * FROM `wp_usermeta` 
WHERE meta_key= 'referrer' AND 
meta_value LIKE '%270%' AND 
meta_key= 'view_type' AND 
meta_value LIKE '%invoice%'

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.