Php 将所有图像附加到任何帖子

Php 将所有图像附加到任何帖子,php,wordpress,Php,Wordpress,我通过以下方式获得所有图像的列表: $the_query = new WP_Query( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => -1, ) ); 但我只想让那些上传到我网站上帖子的人 不是附加到特定帖子的图像,而是排除那些没有在任何帖子中出现的

我通过以下方式获得所有图像的列表:

$the_query = new WP_Query( array(
  'post_type'       => 'attachment',
  'post_mime_type'  => 'image',
  'post_status'     => 'inherit',
  'posts_per_page'  => -1,
 ) );
但我只想让那些上传到我网站上帖子的人


不是附加到特定帖子的图像,而是排除那些没有在任何帖子中出现的图像。

您所要做的就是将以下代码粘贴到一个循环中

$args = array(
        'post_parent'    => get_the_ID(), // your post id
        'post_type'      => 'attachment',
        'numberposts'    => -1, // show all
        'post_status'    => 'any',
        'post_mime_type' => 'image',
        'orderby'        => 'menu_order',
        'order'           => 'ASC'
   );

$images = get_posts($args);
if($images) { ?>
    <img src="<?php echo wp_get_attachment_url($image->ID); ?>" />
<?php
}
?>
$args=array(
'post\u parent'=>获取\u ID(),//您的post ID
“post_类型”=>“附件”,
'numberposts'=>-1,//全部显示
“post_状态”=>“任何”,
“post_mime_type”=>“image”,
'orderby'=>'菜单\u顺序',
“订单”=>“ASC”
);
$images=get_posts($args);
如果($images){?>
ID);?>“/>

我认为post\u mime\u类型不正确

$args = array(
    'post_type'  => 'attachment',
    'post_status'    => 'inherit',
    'post_mime_type' => 'image/gif',
);

$query = new WP_Query( $args );

希望这能有所帮助!

事实上,有些图片似乎被遗漏了,没有任何帮助reason@Archipel您能打印($images)并检查一下吗?