It seems pretty hacky, but this does work in my testing (I tested with built-in page
post type):
// Change the post list and search query.
add_action( 'pre_get_posts', static function ( $query ) {
if ( ! is_admin() || ! $query->is_main_query() ) {
return;
}
if ( ! in_array( $query->get( 'post_type' ), array( 'post', 'Array' ) ) ) {
return;
}
$query->set( 'post_type', array( 'post', 'page' ) );
} );
// If `post_type` is set to `Array`, change back to `post` to satisfy core validation.
add_action( 'admin_init', static function () {
if ( ! isset( $_GET['s'] ) || '/wp-admin/edit.php' !== $_SERVER['PHP_SELF'] || ! isset( $_GET['post_type'] ) || 'Array' !== $_GET['post_type'] ) {
return;
}
$_GET['post_type'] = 'post';
$_REQUEST['post_type'] = 'post';
} );
The main functional piece here is checking the $_GET['post_type']
value on the admin_init
action, and if it’s equal to Array
, then change it to post
(to satisfy WP core). Then when the query is actually constructed, change the post_type
parameter to both post types.