如何在Wordpress的库中显示任何类型的媒体?
看看这个问题,它得到了额外的评论。但我会抄一些重要的东西来回答你的问题——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;
}