SQL to fetch attachment image with parent post
-
I need to construct a SQL query that will, given a list of image-attachment post ID’s, fetch me the URL of the image thumb, and the title and excerpt of the parent post.
I’m guessing it’ll be something like:
SELECT image_posts.image_url parent_posts.post_title parent_posts.post_excerpt FROM wp_posts AS image_posts INNER JOIN wp_posts AS parent_posts ON image_posts.post_parent = parent_posts.ID WHERE image_posts.ID IN (123, 456)
I’d like to ask:
1. Am I reinventing the wheel? There’s not a WP function that’ll do this for me, right?
2. Assuming I do need a custom query for this, then am I approaching it in the right way?
3. I clearly need some help turning the pseudo-code query above into something that will actually return fields from the WP database. Any assistance here would be greatly appreciated.Ta ??
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘SQL to fetch attachment image with parent post’ is closed to new replies.