$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\');
一个相关的解决方案,在不提供帖子ID的情况下查询帖子(按帖子日期排序,并使用wp\\udatabase前缀):
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