【发布时间】:2016-11-18 14:02:42
【问题描述】:
我在 WordPress 中创建了一个自定义帖子类型,但想知道是否可以指定特定于自定义帖子类型的上传目录,以及在执行和插入媒体时,媒体库仅显示上传到特定目录的媒体自定义帖子类型。
将图像保存在,媒体库仅显示媒体:
/wp-content/uplodas/custom_post_type/
更新
我有以下代码将过滤我正在寻找的内容但是我只想在我在 client_gallery 的 CPT 上运行过滤器。我的 if 语句似乎不起作用?
function wpse48677_get_cpt()
{
if ($_GET['post_type'] == "") {
$posts = $_GET['post'];
$postType = get_post_type($posts);
} else {
$postType = $_GET['post_type'];
}
return $postType;
}
function my_posts_where($where)
{
global $wpdb;
$post_id = false;
if (isset($_POST['post_id'])) {
$post_id = $_POST['post_id'];
$post = get_post($post_id);
if ($post) {
$where .= $wpdb->prepare(" AND my_post_parent.post_type = %s ", $post->post_type);
}
}
return $where;
}
function my_posts_join($join)
{
global $wpdb;
$join .= " LEFT JOIN {$wpdb->posts} as my_post_parent ON ({$wpdb->posts}.post_parent = 'client_gallery') ";
return $join;
}
function my_bind_media_uploader_special_filters($query)
{
add_filter('posts_where', 'my_posts_where');
add_filter('posts_join', 'my_posts_join');
return $query;
}
print wpse48677_get_cpt();
if(wpse48677_get_cpt() == 'client_gallery') {
// THIS IF STATEMENT DOESNT SEEM TO WORK? I KNOW $doJoin == client_gallery
// AS I CAN SEE IT IF I PRINT IT OUT (see above)
// IF I RUN THE ADD FILTER WITHOUT THE IF I GET THE RESULTS I"M LOOKING FOR?????
add_filter('ajax_query_attachments_args', 'my_bind_media_uploader_special_filters');
}
【问题讨论】:
-
您可以在上传中创建文件夹并从特定文件夹加载。
-
我如何从特定文件夹加载并且仅在我从自定义帖子类型添加或编辑时加载?