Skip to content

Instantly share code, notes, and snippets.

@farrukhmomin
Last active May 8, 2020 07:17
Show Gist options
  • Save farrukhmomin/70bb3780e98501418575 to your computer and use it in GitHub Desktop.
Save farrukhmomin/70bb3780e98501418575 to your computer and use it in GitHub Desktop.
SQL Query to get Latest Wordpress Post with Featured Image.
select DISTINCT wp_posts.id, wp_posts.post_title, wp_posts.post_content, wp_posts.post_type, featured_image.guid as post_image, wp_posts.post_modified, wp_users.display_name
from wp_posts
inner join wp_postmeta on wp_posts.id = wp_postmeta.post_id and wp_postmeta.meta_key = '_thumbnail_id'
inner join wp_posts as featured_image on featured_image.id = wp_postmeta.meta_value
inner join wp_users on wp_users.id = wp_posts.post_author
where wp_posts.post_status = 'publish'
order by wp_posts.ID desc
limit 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment