I'de like to have a mysql query on a wordpress database that recover the title and the first image link of the last 6 posts.
Wordpress core functions are not permitted because I'd like to show them on an external site. In other words I need the pure mysql query.
I'm able to show the titles in this way:
$result = mysql_query("select * FROM wp_posts WHERE post_status='publish' AND post_type='ad_listing' ORDER BY id desc limit 6" ,$db);
while ($records = mysql_fetch_assoc($result)) {
echo '<li>'.$records['post_title'] ."</li>";
}
But how to recover the first image (if exists) attached to these posts?