I have been trying to fetch posts from a wordpress site’s mysql db to my own script for a few days.
<?php
$querystr = "
SELECT DISTINCT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = 'tag'
AND $wpdb->postmeta.meta_value = 'email'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_date < NOW()
ORDER BY $wpdb->posts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
?>
I can see thumbnail images on the original site but I could not figure out where to get that image location data in the db.
What would be the enhancements on my query in order to have image information with current ones?
You need to dive into your wp_postmeta table. This is where you will find everything. You can get the thumbnail ID with the following query:
You will get a thumbnail ID from which you will be able to get your real thumbnail with the following query:
This will actually give you two rows :
(meta_key="_wp_attached_file")
(meta_key="_wp_attachment_metadata")
Try this code:
More details here: http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail