Php 自定义帖子类型特定媒体-WordPress
我在WordPress中创建了一个自定义帖子类型,但不知道是否可以指定一个特定于自定义帖子类型的上传目录,以及在执行和插入媒体时,媒体库仅显示上传到自定义帖子类型的特定目录中的媒体 将图像保存在中,媒体库仅在中显示媒体:Php 自定义帖子类型特定媒体-WordPress,php,wordpress,Php,Wordpress,我在WordPress中创建了一个自定义帖子类型,但不知道是否可以指定一个特定于自定义帖子类型的上传目录,以及在执行和插入媒体时,媒体库仅显示上传到自定义帖子类型的特定目录中的媒体 将图像保存在中,媒体库仅在中显示媒体: /wp-content/uplodas/custom_post_type/ 更新 我有下面的代码,它将过滤我正在寻找的内容,但是我只想在客户端的CPT上运行过滤器。我的if station似乎不起作用 function wpse48677_get_cpt() { i
/wp-content/uplodas/custom_post_type/
更新
我有下面的代码,它将过滤我正在寻找的内容,但是我只想在客户端的CPT上运行过滤器。我的if station似乎不起作用
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');
}
如果在自定义帖子类型声明发生的任何地方添加此代码,您将为自定义帖子类型创建上载目录。每次从属于您的帖子类型的帖子上传时,也会使用此文件夹
function super_upload_dir( $args ) {
if(!isset($_REQUEST['post_id']) || get_post_type( $id ) != $YOUR_POST_TYPE)
return $args;
$id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' );
if( $id ) {
$newdir = '/' . $DIRECTORY_NAME;
$args['path'] = str_replace( $args['subdir'], '', $args['path'] );
$args['url'] = str_replace( $args['subdir'], '', $args['url'] );
$args['subdir'] = $newdir;
$args['path'] .= $newdir;
$args['url'] .= $newdir;
}
return $args;
}
add_filter( 'upload_dir', 'super_upload_dir' );
对于Library过滤器,我过去使用的插件可以根据短代码过滤媒体项,但我不知道如何根据后端的当前帖子类型进行过滤。抱歉您可以在“上载”中创建文件夹,并从特定文件夹加载。如何从特定文件夹加载,以及仅在im从自定义帖子类型添加或编辑时加载?