How to get post image?
-
Hi all,
I am developing an archive footer and I need to get the image with a post.
This code works for title and text but not for the image src,
$lastPosts = $wpdb->get_results("SELECT ID, post_title, post_content, meta_value FROM $wpdb->posts LEFT JOIN $wpdb->postmeta on wp_posts.ID = wp_postmeta.post_id WHERE post_status = 'publish' ORDER BY id DESC LIMIT 0,$i");
if($lastPosts) {
foreach($lastPosts as $lastPost) {
$id = $lastPost->ID;
$img = get_post_meta($id, '_wp_attached_file', 1);
$link = get_permalink($lastPost->ID);
etc.
}}Any tips?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘How to get post image?’ is closed to new replies.