获取所有附件:
$attachments = get_posts( array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
) );
检查每个附件的附件“父级”。
foreach($attachments as $attachment){
$parentID = $attachment->post_parent;
$postID = $post->ID;
if($parentID == $postID){
//your code here
echo \'This attachment belongs to the current post.\';
}
}
但是如果您已经有了附件,那么您所需要的就是:注意:“have”是指您以前查询过它或将其保存到对象中。
$parentID = $attachment->post_parent;
$postID = $post->ID;
if($parentID == $postID){
//your code here
echo \'This attachment belongs to the current post.\';
}