Custom SQL query to get List of posts with featured image url

0
260

"SELECT wp_28_posts.id,
wp_28_posts.post_title,wp_28_posts.post_content,wp_28_posts.post_modified,wp_28_posts.post_name,
wp_28_terms.name,
(SELECT guid
FROM wp_28_posts
WHERE id = wp_28_postmeta.meta_value) AS image
FROM wp_28_posts,
wp_28_postmeta,
wp_28_term_relationships,
wp_28_terms
WHERE wp_28_posts.id = wp_28_term_relationships.object_id
AND wp_28_terms.term_id = wp_28_term_relationships.term_taxonomy_id
AND wp_28_terms.name = 'blog'
AND wp_28_posts.post_status = 'publish'
AND wp_28_posts.post_type = 'post'
AND wp_28_postmeta.post_id = wp_28_posts.id
AND wp_28_postmeta.meta_key = '_thumbnail_id'
ORDER BY wp_28_posts.post_date DESC
LIMIT 10"

if ($qry->num_rows() > 0) {
$data = array();

foreach($qry->result_array() as $res){

}}