how to add display_name from the users table to this query

You should be able to do something like this, by adding in another join, and selecting the display_name column from that joined table:

SELECT a.post_title, b.meta_key, b.meta_value as level, c.meta_value as intro, u.display_name
FROM wp_posts a
LEFT JOIN wp_postmeta b ON a.ID = b.post_id
LEFT JOIN wp_postmeta c ON a.ID = c.post_id
LEFT JOIN wp_users u ON a.post_author = u.ID
WHERE b.meta_key = 'level'
AND c.meta_key = '_post_main_intro'

Hopefully this works for you!

Leave a Comment