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?

3
  • A single meta key can't have two different names and values at the same time, I think you want some ORs in there. Commented Dec 6, 2016 at 3:58
  • You need one join per meta key - out of interest, why are you using SQL and not WP_Query? Commented Dec 6, 2016 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. Commented Dec 22, 2016 at 7:42

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.