如何在Wordpress中的图库中显示任何类型的媒体?
答案 0 :(得分:0)
看看这个问题,它得到了额外的评论。但我会复制重要的事情来回答你的问题 - https://wordpress.stackexchange.com/questions/11662/get-all-images-in-media-gallery
这样就可以获得媒体库中的所有附件;
$media_query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
)
);
$list = array();
foreach ($media_query->posts as $post) {
$list[] = wp_get_attachment_url($post->ID);
}
// do something with $list here;
或者只获取特定类型的所有项目;
$query_images_args = array(
'post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => 'inherit', 'posts_per_page' => -1,
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= $image->guid;
}