Skip to content

Instantly share code, notes, and snippets.

@ljanecek
Forked from anonymous/gist:38a56d1749a9982e6b5a
Last active September 9, 2015 13:16
Show Gist options
  • Select an option

  • Save ljanecek/eba7c44b6dc518458951 to your computer and use it in GitHub Desktop.

Select an option

Save ljanecek/eba7c44b6dc518458951 to your computer and use it in GitHub Desktop.
How to find Wordpress featured images together with respective post directly from DB query (for imports, migrations etc.)
SELECT p.*
FROM wp_postmeta AS pm
INNER JOIN wp_posts AS p ON pm.meta_value=p.ID
INNER JOIN wp_posts AS parent ON p.post_parent = parent.`ID`
WHERE pm.meta_key = '_thumbnail_id'
AND parent.post_status = 'publish'
/* You can add more conditions for posts like post type etc. */
ORDER BY p.post_date DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment