对我来说,一个有效的解决方案是在显示媒体库时向Wordpress查询中添加一个子句。
在浏览Wordpress数据库时,我注意到wp_posts.post_type = \'attachment\'
存储在wp_posts.guid
柱
add_filter(\'posts_where\', \'limitMediaLibraryItems_56456\', 10, 2 );
function limitMediaLibraryItems_56456($where, &$wp_query) {
global $pagenow, $wpdb;
// Do not modify $where for non-media library requests
if ($pagenow !== \'media-upload.php\') {
return $where;
}
$where .= " AND {$wpdb->posts}.guid LIKE \'%my-path-segment%\'";
return $where;
}