I know you can use the wordpress methods for getting a featured image, however with this particular project I need to get the featured image via mysql query. Can anyone point me in the right direction. Thank you.

This is what I have so far but my query is not doing the trick. I have the $post->id stored as a variable called $da_id

            $Featured_image = $wpdb->get_results("
            SELECT *
            FROM net_5_postmeta  
            INNER JOIN net_5_posts ON net_5_postmeta.post_id=net_5_posts.ID 
            WHERE post_parent = $da_id
            AND meta_key = '_wp_attached_file' 
            ORDER BY post_date 
            DESC LIMIT 15",'ARRAY_A');

2 s
2

$Featured_image = $wpdb->get_results("
    SELECT p.*
      FROM net_5_postmeta AS pm
     INNER JOIN net_5_posts AS p ON pm.meta_value=p.ID 
     WHERE pm.post_id = $da_id
       AND pm.meta_key = '_thumbnail_id' 
     ORDER BY p.post_date DESC 
     LIMIT 15
",'ARRAY_A');

Leave a Reply

Your email address will not be published. Required fields are marked *