I am trying to code up a page that will display the title, featured image and permalink of published pages that utilise a certain template.
SQL is not my strong point, so far I have managed to write a script that will call the titles of the posts that come from a certain template using a join, but I am stuck on also outputting the featured image associated with the post.
Can someone help please?
Here is what I have muddled together so far
<?php
$querystr = "
SELECT $wpdb->posts.id, $wpdb->posts.post_title, $wpdb->postmeta.meta_value
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_date < NOW()
AND $wpdb->postmeta.meta_value = 'scheme.php'
ORDER BY $wpdb->posts.post_date DESC
";
$theposts = $wpdb->get_results($querystr);
foreach ($theposts as $pageresult) {
echo '<p>' .$pageresult->post_title. '</p>';
}
?>