I need help putting together an SQL that can delete users if they don't have (metakey1 or metakey2) and (does not have comments)
I have this SQL which does it for single meta_key
SELECT *
FROM wp_users LEFT JOIN wp_usermeta
ON wp_users.ID = wp_usermeta.user_id
AND wp_usermeta.meta_key = 'metakey1'
WHERE wp_usermeta.user_id IS NULL
How can i extend the above SQL to do that?
I need help putting together an SQL that can delete users if they don't have (metakey1 or metakey2) and (does not have comments)
I have this SQL which does it for single meta_key
SELECT *
FROM wp_users LEFT JOIN wp_usermeta
ON wp_users.ID = wp_usermeta.user_id
AND wp_usermeta.meta_key = 'metakey1'
WHERE wp_usermeta.user_id IS NULL
How can i extend the above SQL to do that?
Share Improve this question asked Mar 12, 2019 at 22:54 Guru SurferGuru Surfer 11 bronze badge 3 |1 Answer
Reset to default 0So i got the answer and solution here https://stackoverflow/questions/55142768/sql-for-wp-to-delete-users-with-multiple-meta-keys-and-comments/55142835#55142835
SELECT u.*
FROM wp_users u
WHERE NOT EXISTS (SELECT 1
FROM wp_usermeta um
WHERE u.ID = um.user_id AND
um.meta_key IN ('metakey1', 'metakey2')
) AND
NOT EXISTS (SELECT 1
FROM wp_comments c
WHERE u.ID = c.user_id
);
get_user_meta
andWP_User_Query
? What you're wanting to do is going to result in a super expensive/slow query that probably won't finish in the time limit PHP has, and cause many issues ( assuming it can be understood ). Additionally, can you provide some context? What problem does this solve for you? – Tom J Nowell ♦ Commented Mar 13, 2019 at 1:27