I'm currently trying to get all users from wp_users that have no matching ID entry in wp_usermeta (matching on user_id).

I have a site with a very large user base that currently has thousands of spam users.

The following query is returning no records:

SELECT * FROM wp_users
SELECT user_id FROM wp_usermeta);

I've already removed the bad records from the meta table which is why I need to query to find only the records with no associated ID in wp_users.

1 Answer 1

$user_query = new WP_User_Query( array ( 'orderby' => 'ID', 'order' => 'DESC' ) );
if ( ! empty( $user_query->results ) ) {
    foreach ( $user_query->results as $user ) {
        echo '<p>'. $user->ID . '</p>';
} else {
    echo 'No users found.';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.