Created
November 26, 2011 22:54
-
-
Save alanedwardes/1396447 to your computer and use it in GitHub Desktop.
Evil bit of SQL to get the most recent posts from WordPress with media, the link to the media and the post ID.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT posts.post_title, posts.ID post_id, media.ID media_id | |
FROM $wpdb->posts media | |
JOIN $wpdb->posts posts | |
ON posts.post_content LIKE CONCAT('%', media.guid, '%') | |
WHERE media.post_type = 'attachment' | |
AND posts.post_type = 'post' | |
AND posts.post_status = 'publish' | |
GROUP BY posts.ID | |
ORDER BY media.post_date DESC | |
LIMIT 0, 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment