• Here is the query i wrote to grab thumbnails, but it doesn’t seem to be grab “featured image”. Can any one help ?

    SELECT post.ID, post.post_title, post.post_content, attachment_meta.meta_value AS upload_relative_path
    FROM wp_posts AS post LEFT JOIN wp_postmeta AS post_meta ON (post_meta.post_id = post.ID AND
    post_meta.meta_key = '_thumbnail_id') LEFT JOIN wp_postmeta AS attachment_meta ON
    (attachment_meta.post_id = post_meta.meta_value AND attachment_meta.meta_key = '_wp_attached_file')
    WHERE post.post_status = 'publish'  AND post.post_type = 'post' and post.id in( 8673)

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php // Insert featured image
    		if (has_post_thumbnail()) {
    		the_post_thumbnail('medium', array(
    		'class' => 'class_here',
    		'title' => ''));
    	} // endif
    ?>

    This should display a featured image if you have one…

    dtrickky, he’s trying to query the database directly. Sravsk, here’s what you need:

    SELECT
    	p1.*,
    	wm2.meta_value
    FROM
    	wp_posts p1
    LEFT JOIN
    	wp_postmeta wm1
    	ON (
    		wm1.post_id = p1.id
    		AND wm1.meta_value IS NOT NULL
    		AND wm1.meta_key = "_thumbnail_id"
    	)
    LEFT JOIN
    	wp_postmeta wm2
    	ON (
    		wm1.meta_value = wm2.post_id
    		AND wm2.meta_key = "_wp_attached_file"
    		AND wm2.meta_value IS NOT NULL
    	)
    WHERE
    	p1.post_status="publish"
    	AND p1.post_type="post"
    ORDER BY
    	p1.post_date DESC
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘MYSQL query to grab featured image’ is closed to new replies.