I have added a filter on pre_get_posts
to merge a custom post type with the regular posts in the edit-post screen.
All posts are listed but when I try to filter these posts by category, I got an
“invalid post type” error.
Indeed, the post_type
parameter in the query string is set to “(...)&post_type=Array(...)"
Is this possible using some other hook or filter?
// 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' );
Thanks for you help