当您从帖子编辑屏幕上传附件时,WordPress将当前帖子ID设置为post_parent
附件的。这就是您获取这些附件的方式:
$post_ID = 123;
$attachments = get_posts(
array(
\'post_type\' => \'attachment\',
\'post_status\' => \'inherit\',
\'post_parent\' => $post_ID,
\'post_per_page\' => -1,
\'post_mime_type\' => \'image/*\'
)
);
foreach ( $attachments as $a ) {
$info = wp_get_attachment_image_src( $a->ID, \'full\' );
$info[ 0 ]; // url to the image
$info[ 1 ]; // image with in px
$info[ 2 ]; // image height in px
$info[ 3 ]; // TRUE if the image is a resized one
dump( $info[ 0 ] );
}
食品法典
wp_get_attachment_image_src()