【发布时间】:2014-10-28 08:17:03
【问题描述】:
我想在单独的页面上显示每个 Wordpress 帖子中的图像。
当使用get_children(或get_posts)时,'post_type' => 'attachment' 仅在我刚刚将图像(通过 WP 的“添加媒体 > 上传文件”)上传到该特定帖子时才有效。
如果我将现有图像添加到我的 WP MEDIA LIBRARY 中已经存在的帖子中,它将不起作用)。
'attachment' 是否可以用于现有(已上传)图像?
查看我的测试功能:
function echo_first_image($postID){
$args = array(
'post_type' => 'attachment',
'post_parent' => $postID
);
$attachments = get_children( $args );
if($attachments){
echo'YES'; // test answer
}else{
echo'NO'; // test answer
}
}
编辑:作为“附件”的每个“post_type”都有一个“post_parent”——这是否意味着附件只能有一个父级?
【问题讨论】:
标签: wordpress