题
在我的functions.php中,我需要列出上传文件夹中的所有图像,这些图像当前未连接到WP数据库中的帖子。
看来,每次将图像上传到WP上传文件夹(通过FTP或通过媒体管理器)时,记录就会插入WP数据库中,对吗?
如何获得当前未附上任何帖子的所有图像的列表?
解决方案
这应该有效:
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => 0
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
setup_postdata($post);
the_attachment_link($post->ID);
}
}
其他提示
如果您需要在UI中进行管理:
/wp-admin/upload.php?detached=1
将地址添加到您的博客上。
或更多描述性:
登录您的管理员,然后使用菜单: 媒体 -> 图书馆. 。选择 无关 链接列表的过滤器下拉。