Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Forked from farrukhmomin/WP-Query
Created September 23, 2018 14:59
Show Gist options
  • Save hoangitk/94b47afa52e63ce2929295bfe89a47e2 to your computer and use it in GitHub Desktop.
Save hoangitk/94b47afa52e63ce2929295bfe89a47e2 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