Get featured image of post in wordpress using Mysql query


[code langauage=”css”]

Now i am sharing a code to get the featured image URL of a post in wordpress using sql query.
follow this process

In following query, replace $post_id with your postid variable. (If you are planning to extract full row., replace guid with *)

$query =” SELECT p.guid FROM wp_postmeta AS pm INNER JOIN wp_posts AS p ON pm.meta_value=p.ID
WHERE pm.post_id = $post_id
AND pm.meta_key = ‘_thumbnail_id’
ORDER BY p.post_date DESC
LIMIT 15″;
$sql = mysql_query($query);


while($result = mysql_fetch_array($sql)){

//echo “THe post ID is “.$post_id;
echo “<img class=’wishlistimage’ src=’”.$result[0].”‘ alt=’sample’ />”;


Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.