I found a workaround for this by
- creating a function to query all post types in PHP
- passing this data as a var via a localized script into the block editor
- mapping this var and calling the getEntityRecords for each one
- pushing that into an array to use as needed
Code snippets below.
PHP
function get_all_post_types() {
$post_types_arr[];
$post_types = get_post_types(array(
'public' => true,
), 'objects');
// sort post types by name
uasort($post_types, function($a, $b) {
return strcmp($a->labels->name, $b->labels->name);
});
foreach ($post_types as $post_type) {
array_push($post_types_arr, $post_type);
}
return $post_types_arr;
}
add_action( 'init', 'include_posttype_array_in_blocks_on_init' );
function include_posttype_array_in_blocks_on_init() {
$asset_file = include( __DIR__ . 'build/index.asset.php' );
wp_register_script(
'posttypes-for-blocks',
__DIR__ . '/build/index.js',
$asset_file['dependencies'],
$asset_file['version']
);
wp_localize_script(
'posttypes-for-blocks',
'postTypeVars',
array(
'postTypes' => get_all_post_types()
)
);
}
In the block edit.js file
let data = [];
const postTypes = postTypeVars.postTypes;
const posts = postTypes.map( ( postType ) => {
const post = useSelect( ( select ) => {
return select( 'core' ).getEntityRecords( 'postType', postType, args );
});
data.push( post );
} );
// flatten the array into one array
data = data.flat();
Now you can do whatever you want with the post data.