I need some SQL help to pull some data out of my Wordpress database
Posted on 2013-01-08
If you know what you're doing, this should be quite simple...
In English, I need a list of posts and the the file paths to the images associated with the posts.
There are two tables involved: wp_posts and wp_postmeta
The two types of relevant rows in wp_posts are "posts", which have the value of "publish" in the post_status column, and "images", which have the value of "inherit" in the post_status colum.
The values I need from the wp_posts table are the ID, post_date, and post_title
If an image is associated with a post, the post_parent column of the image's row will have the value of the ID column from the post's row. (The post_parent value for a post is 0.)
The file path of the image is found in the meta_value column of the wp_postmeta table and is identified by having the value "_wp_attached_file" in the meta_key column.
The wp_postmeta table is linked to the wp_posts table by its post_id column.
What I'm try to ask is:
Give me all the post IDs, post_dates, and post_titles
Where the post has linked posts that are images (post_status = "inherit")
And while you're at it, give me the paths to those image files.
Hopefully, this is enough for someone who knows what they're doing to pull some decent SQL together for me. If you need anything more to work with, just let me know.