Hi @Holidaymaine:
Here’s the query you are looking for:
<?php
include( '../wp-load.php' );
$sql =<<<SQL
SELECT DISTINCT
u.user_email AS user_email,
um.meta_value AS user_lastname
FROM
{$wpdb->users} AS u
LEFT JOIN {$wpdb->usermeta} AS um ON u.ID = um.user_id
LEFT JOIN {$wpdb->posts} AS p ON u.ID = p.post_author
LEFT JOIN {$wpdb->term_relationships} AS tr ON p.ID = tr.object_id
LEFT JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
LEFT JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id
WHERE 1=1
AND u.user_status="0"
AND um.meta_key = 'last_name'
AND um.meta_value="%s"
AND t.slug = '%s'
SQL;
$sql = $wpdb->prepare( $sql, 'Smith', 'baseball' );
$usersemails = $wpdb->get_results( $sql );
header( 'Content-type:text/plain' );
print_r( $usersemails );
Related Posts:
- WordPress SQL Issue not returning correct reselts
- How to get image path from id using SQL
- LEFT JOIN, INNER OUTER JOIN, LEFT OUTER JOIN is driving me crazy. Please help?
- Search multiple meta keys at once
- Getting users who registered 360 days from current date
- mysql query two database tables, users and usermeta and sort by custom meta int value
- Get emails from users by custom field SQL
- SELECT from wp_users, get Displayname too
- Safely changing UserID’s, re-using deleted UserID’s and automatically using deleted userID’s instead of an increment
- user_login vs. user_nicename
- How to programatically change username (user_login)?
- Difference between update_user_meta and update_user_option
- get_user_meta() doesn’t include user email?
- Automatically delete inactive users after 2 months
- How to display custom user meta from registration in backend?
- Allowing an email as the username?
- Grouping users under parent user
- How to create a template for a custom URI associated with the user
- How to order users alphabetically by their last name?
- Extending WP_User class and using this sub-class during the whole lifecycle
- Wp_User_Query not sorting by meta key
- How we can get the user id by its display_name
- WP_User_Query with combined meta query – not working?
- How to use hyperdb to separate and share a user dataset between wordpress installs?
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- Show Biographical Info while creating new user
- include user profiles in search results?
- How to add follow functionality to multi-author wordpress site?
- Where to Store Custom User Fields
- Plugin that would allow WordPress Authors to “follow” other Authors and query “Activity Info” from that
- How to delete users with no order history through phpmyadmin sql?
- User profile custom field
- Front end user meta options for users
- ACF Upload Image in front-end with custom form
- Hide a user from WordPress
- Drop down list in user profile page
- Check for user meta data at Login
- Creating a Front-end based User Search
- How to get top 10 user is based on user meta value
- Searchable meta value in user.php
- How to add country drop down menu to the user profile?
- Delete user from frontend
- Add custom fields to the user profile
- Exclude subscriber users from user list
- Memory usage for scalable usermeta queries
- stop login if user_status equal zero
- Does wp_delete_user() remove all user content?
- WP User Query fails when searching meta queries and search columns
- Log all users out of all locations after 24 hours
- How can i create an array user meta?
- How to set show admin bar front to true for all users?
- Add user data to table when user is created?
- User Last Login Sort Column
- Updating user meta
- In what part of the WordPress core does the users table and usermeta table get joined?
- WordPress User Meta & ChromePHP or other way to debug/view php variables
- Modify Database in Multi-Site wp_usermeta table
- Use wp_update_user to update custom column in wp_users table
- Are User Levels Still Currently Used?
- WPML Default Language User Meta [closed]
- Display users in order by an “order” custom meta field
- Search Users base on meta_value & meta_key
- Rest API code to get ID of current user not working: get_current_user_id() gives 0
- Updating wp_user_level on user update
- Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
- User Meta Data in a Sortable Table
- get_user_meta an ID for multiple functions
- How can I attach a user to another user with user meta
- Column Sorting Code on users.php
- Creating user without username and password
- List users by meta_key and meta_value
- How change user type from contributor to author
- Is this code true or not
- users and usermeta table
- How to get last user with wpdb?
- User description only displayed for logged user
- The Simple and Correct Way to Add User Meta
- How to pull all the contributer users records and order by Designation (which is users meta data)?
- cannot get user_registered date from get_user_meta
- How to copy user_nicename value into user_login
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- “the_author_meta(‘url’)” not working inside “href”
- Assign random (and unique) user meta upon registration
- SQL Bulk update all WordPress user’s nicknames to firstname + lastname format
- Display the line breaks in user bio without using html
- how to set default update_user_meta values wordpress
- Querying specific table row by current user login
- Get user by meta key – WP multi site
- Add custom user meta data
- Cannot Update user meta in custom field
- Can I Create a Second Admin Level User Role?
- How to delete a particular row in a database table
- How to add an attribute to a user?
- Adding fields to the “Add New User” but the form data not saved into DB
- New User Save Filter
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- how do I add role and capability after I create a new user
- User Meta stuff
- How to relate the Category to user?
- What does “link” refer to when you delete a user?