任何人都可以建议我获取为 wordpress 存储的所有图像的功能是什么?我只需要列出在 wordpress 管理员的菜单媒体下看到的所有图像。
提前致谢
最佳答案
上传的图像存储为“附件”类型的帖子;使用具有正确参数的 get_posts()。在 the Codex entry for get_posts() ,这个例子:
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
setup_postdata($post);
the_title();
the_attachment_link($post->ID, false);
the_excerpt();
}
}
?>
...遍历所有附件并显示它们。
如果您只想获取图像,正如 TheDeadMedic 评论的那样,您可以使用
'post_mime_type' => 'image'
进行过滤。在论据中。
关于wordpress - 得到wordpress所有媒体文件的功能是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3307576/