Wordpress SQL Query to get post meta data


Scenario:

You want to query a Wordpress database and get out ther pertinent information related to the current version of a post. The following query works and has been tested with both MySql and a SQLite implementation with Wordpress 4.0. It is look for published posts and pulling back the main information on the post plus who authored it.

SQL:

select wp.ID, 
	post_date, 
	post_modified,
	post_content,
	post_title,
	post_name,
	display_name
from wp_posts wp
left outer join wp_users wu on wu.ID = wp.post_author
where post_status = 'publish' and post_type = 'post'

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.