diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index b6746e4b626d0..4c446af5c6ac5 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -1179,20 +1179,17 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' ) unset( $template_files_query['post_type'] ); $template_files = _get_block_templates_files( $template_type, $template_files_query ); foreach ( $template_files as $template_file ) { - if ( - ! isset( $query['post_type'] ) || - ( isset( $query['post_type'] ) && isset( $template_file['postTypes'] ) && in_array( $query['post_type'], $template_file['postTypes'], true ) ) - ) { - $query_result[] = _build_block_template_result_from_file( $template_file, $template_type ); - } - - // The custom templates with no associated post types are available for all post types. - if ( isset( $query['post_type'] ) && ! isset( $template_file['postTypes'] ) ) { + if ( isset( $query['post_type'] ) && ! isset( $template_file['postTypes'] ) ) { // The custom templates with no associated post types are available for all post types. $candidate = _build_block_template_result_from_file( $template_file, $template_type ); $default_template_types = get_default_block_template_types(); if ( ! isset( $default_template_types[ $candidate->slug ] ) ) { $query_result[] = $candidate; } + } elseif ( + ! isset( $query['post_type'] ) || + ( isset( $query['post_type'] ) && isset( $template_file['postTypes'] ) && in_array( $query['post_type'], $template_file['postTypes'], true ) ) + ) { + $query_result[] = _build_block_template_result_from_file( $template_file, $template_type ); } }