I am struggling with a select query for wordpress, which is not working. The weird part is that I have 2 select queries, 1 at a current running website and works. And an almost similar select query on a local test machine and is not working.

Here is the query from the live, which is working:
SELECT DISTINCT users.* FROM wp_users as users INNER JOIN wp_usermeta as mt ON (users.ID = mt.user_id) WHERE 1=1 AND (mt.meta_value LIKE '%Trainer%') AND (mt.meta_key = '_upme_search_cache' AND mt.meta_value LIKE '%ACTIVE%') AND ( (mt.meta_key = '_upme_search_cache' AND mt.meta_value NOT LIKE '%administrator%') AND (mt.meta_key = '_upme_search_cache' AND mt.meta_value NOT LIKE '%sportentrainer%') ) ORDER BY users.user_registered asc LIMIT 9

And here the query from the local machine:
SELECT DISTINCT users.* FROM wp_users as users INNER JOIN wp_usermeta as mt ON (users.ID = mt.user_id) WHERE 1=1 AND (mt.meta_value LIKE '%trainer%') AND (mt.meta_key = 'sent_activation_status' AND mt.meta_value LIKE '%ACTIVE%') AND ( (mt.meta_key = 'account_type' AND mt.meta_value NOT LIKE '%administrator%') OR (mt.meta_key = 'account_type' AND mt.meta_value NOT LIKE '%sportentrainer%') ) ORDER BY users.user_registered asc LIMIT 9

The meta_key on the second query are all found when searching for them separately. You notice that the meta_keys are different, but that is not the problem.

The first query runs on a live version of phpmyadmin: 4.1.9 and mysql: 5.0.12 (if I am correct) and the second query runs on the local version of phpmyadmin: 4.6.6 and mysql: 5.6.35

Can someone see why the second query is not working?

Read more here: wordpress select query not working


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: