0

I'm porting a custom PHP feature to be part of a Wordpress plugin.

At present, my USERS table has a field (let's call it FLAG) which my MySQL query needs to filter on, eg:

SELECT custom-data
  FROM custom-table JOIN users ON some-match
 WHERE some-condition AND users.flag='1'
 GROUP BY username

Obviously, within my WordPress plugin, I have implemented flag as user-meta.

But how can I use this in a MySQL query?

0

Without a proper SQL query in the question is not possible to write a proper query in the response, but following your pseudo-code approach:

SELECT custom-data
  FROM custom-table
  LEFT JOIN wp_users ON custom_data.user_id = wp_users.ID
  LEFT JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id
 WHERE some-condition
   AND wp_usermeta.meta_key = 'flag'
   AND wp_usermeta.meta_value = 'flagvalue'

So basically, you need to join against wp_usermeta, which is where you'd be storing your users "flag".

| improve this answer | |

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.