@@ -93,12 +93,11 @@ public function get_block_template_fallback( $template, $id, $template_type ) {
9393 }
9494
9595 $ wp_query_args = array (
96- 'post_name__in ' => array ( 'archive-product ' ),
97- 'post_type ' => $ template_type ,
98- 'post_status ' => array ( 'auto-draft ' , 'draft ' , 'publish ' , 'trash ' ),
99- 'posts_per_page ' => 1 ,
100- 'no_found_rows ' => true ,
101- 'tax_query ' => array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
96+ 'post_name__in ' => array ( 'archive-product ' , $ slug ),
97+ 'post_type ' => $ template_type ,
98+ 'post_status ' => array ( 'auto-draft ' , 'draft ' , 'publish ' , 'trash ' ),
99+ 'no_found_rows ' => true ,
100+ 'tax_query ' => array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
102101 array (
103102 'taxonomy ' => 'wp_theme ' ,
104103 'field ' => 'name ' ,
@@ -109,6 +108,12 @@ public function get_block_template_fallback( $template, $id, $template_type ) {
109108 $ template_query = new \WP_Query ( $ wp_query_args );
110109 $ posts = $ template_query ->posts ;
111110
111+ // If we have more than one result from the query, it means that the current template is present in the db (has
112+ // been customized by the user) and we should not return the `archive-product` template.
113+ if ( count ( $ posts ) > 1 ) {
114+ return null ;
115+ }
116+
112117 if ( count ( $ posts ) > 0 ) {
113118 $ template = _build_block_template_result_from_post ( $ posts [0 ] );
114119
@@ -117,6 +122,7 @@ public function get_block_template_fallback( $template, $id, $template_type ) {
117122 $ template ->slug = $ slug ;
118123 $ template ->title = BlockTemplateUtils::get_block_template_title ( $ slug );
119124 $ template ->description = BlockTemplateUtils::get_block_template_description ( $ slug );
125+ unset( $ template ->source );
120126
121127 return $ template ;
122128 }
0 commit comments