为了清理媒体库,我直接从上载文件夹中删除了一些未使用的图片。现在,每当我转到媒体库时,文件名仍然存在,但缩略图已被删除:https://snag.gy/lzCLiF.jpg
哪里是存储在我的服务器上的图像元数据,以便我可以在那里删除它。
为了清理媒体库,我直接从上载文件夹中删除了一些未使用的图片。现在,每当我转到媒体库时,文件名仍然存在,但缩略图已被删除:https://snag.gy/lzCLiF.jpg
哪里是存储在我的服务器上的图像元数据,以便我可以在那里删除它。
图像url作为附件post\\u类型存储在wp\\u posts中,其相应的post作为父对象。来自Codex,请参阅Template Tags Show All Attachments
我相信这样的东西可以在循环外检索DB中的所有附件:
global $post;
$args = array(
\'post_type\' => \'attachment\',
\'posts_per_page\' => -1,
\'post_status\' => \'any\',
\'post_parent\' => null
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $post ) {
setup_postdata( $post );
the_title();
the_attachment_link( $post->ID, false );
the_excerpt();
}
wp_reset_postdata();
也许像这样的东西可以找到并清除/uploads/directory中不再可用的内容:$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1
);
$attachments = get_posts( $args );
foreach( $attachments as $attch ){
$file = get_attached_file( $attch->ID );
if( !file_exists( $file ) ){
wp_delete_post( $attch->ID, false );
}
}
仔细研究这些问题,就可以很容易地找到实现所需清理的方法。我正在寻找一种方法来编辑当用户选择添加媒体时插入编辑器中的链接。目标是在链接中添加一个具有媒体类型(pdf)的类。我知道如何获取mime类型,但我不确定在插入链接之前使用哪个钩子来检索链接。你能给我指一下正确的方向吗?谢谢