Skip to content

Instantly share code, notes, and snippets.

@ssatz
Forked from hoangitk/WP-Query
Created January 14, 2019 13:09
Show Gist options
  • Save ssatz/c7000c81b8c60697f7dd3af0f5d47423 to your computer and use it in GitHub Desktop.
Save ssatz/c7000c81b8c60697f7dd3af0f5d47423 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
@domianos
Copy link

how can i get posts from specific category with this query?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment