我需要检索图库中图像的URL,基于帖子ID,适合的SQL查询是什么?
我目前在via上找到了如下内容google, 但我不知道如何从外部Wordpress访问全局WP变量-我需要做什么?
function getGallery($id)
{
global $wpdb;
//SQL query to retrieve all attachment of mime type image/jpeg from the given post
$querystr = "
SELECT ID, post_name, guid, meta_value
FROM $wpdb->posts wposts
INNER JOIN $wpdb->postmeta meta ON meta.post_id = wposts.ID AND meta.meta_key = \'_wp_attachment_metadata\'
WHERE wposts.post_type = \'attachment\'
AND wposts.post_parent = \'".$id."\'
AND wposts.post_mime_type = \'image/jpeg\'
";
//get result set from the query
$pictures = $wpdb->get_results($querystr, ARRAY_A);
//return resultset
return $pictures;
}