Skip to content

Instantly share code, notes, and snippets.

@fastmover
Created January 10, 2017 16:28
Show Gist options
  • Select an option

  • Save fastmover/776c07db5e681ec4c562b7500303a62f to your computer and use it in GitHub Desktop.

Select an option

Save fastmover/776c07db5e681ec4c562b7500303a62f to your computer and use it in GitHub Desktop.
Get a WordPress featured image by Post ID, replace 12345 with your post ID.
SELECT
`wp_postmeta_1`.`meta_value`
FROM
`wp_postmeta`
INNER JOIN `wp_postmeta` `wp_postmeta_1`
ON `wp_postmeta`.`meta_value` = `wp_postmeta_1`.`post_id`
WHERE
(`wp_postmeta`.`post_id` = 12345) AND
(`wp_postmeta`.`meta_key` = '_thumbnail_id') AND
(`wp_postmeta_1`.`meta_key` = '_wp_attached_file')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment