Php Wordpress管理员编辑帖子屏幕:按类别过滤自定义帖子和常规帖子

Php Wordpress管理员编辑帖子屏幕:按类别过滤自定义帖子和常规帖子,php,wordpress,Php,Wordpress,我在pre_get_posts上添加了一个过滤器,用于将自定义帖子类型与编辑帖子屏幕中的常规帖子合并。 所有的帖子都列出了,但当我尝试按类别过滤这些帖子时,我得到了一个 “无效的帖子类型”错误 实际上,查询字符串中的post_type参数设置为“(…)&post_type=Array(…)” 这是否可能使用其他挂钩或过滤器 // show custom posts in the admin posts list function Myplugin_posts_add_custom( $query

我在
pre_get_posts
上添加了一个过滤器,用于将自定义帖子类型与编辑帖子屏幕中的常规帖子合并。 所有的帖子都列出了,但当我尝试按类别过滤这些帖子时,我得到了一个

“无效的帖子类型”错误

实际上,查询字符串中的
post_type
参数设置为“
(…)&post_type=Array(…)”

这是否可能使用其他挂钩或过滤器

// show custom posts in the admin posts list
function Myplugin_posts_add_custom( $query ) {

  $screen = get_current_screen();

  if ( is_admin() && $screen->base == 'edit' && $screen->id == 'edit-post' && $screen->post_type == 'post' ) :

    $post_types = array('post', 'my_custom_post'); 
    $query->set( 'post_type', $post_types );

    return $query;
  endif;
}
add_filter( 'pre_get_posts', 'Myplugin_posts_add_custom' );
谢谢你的帮助