I am looking for some help in building a sql to export specific data from the DB.
In BuddyPress, I have a profile field set up called Newsletter. I need to export a list of user from the db who have ticked the Yes (subscribe to newsletter).
I have identified the tables/fields in use in my DB.
SELECT `user_id` FROM `wp_bp_xprofile_data` WHERE `field_id` = 8 AND `value` LIKE 'yes'
Where user_id is the Registered user iD Where field_id 8 is my Newsletter value.
Now I need to link this with wp_user on user_id but don't know how to use 1 SQL on both table (sorry not my stuff).
Second table is wp_user where the Value of User_id should be "linked" to ID.
will appreciate some expert help
SELECT wp_users.ID , wp_users.user_email FROM wp_users LEFT JOIN wp_bp_xprofile_data ON wp_bp_xprofile_data.user_id = wp_users.ID , WHERE wp_bp_xprofile_data.field_id =8 AND wp_bp_xprofile_data.value = 'yes'
Field ID = 8 being the Field you want to get (in my example, newsletter) wp_bp_xprofile_data.value = Yes, being the value of my checkbox (ie Yes)