diff --git a/lib/template-loader.php b/lib/template-loader.php
index c0be22bc75957..f729fe437be5c 100644
--- a/lib/template-loader.php
+++ b/lib/template-loader.php
@@ -93,7 +93,7 @@ function get_template_hierachy( $template_type ) {
function gutenberg_override_query_template( $template, $type, array $templates = array() ) {
global $_wp_current_template_id, $_wp_current_template_content;
- $current_template = gutenberg_find_template_post_and_parts( basename( $template, '.php' ), $templates );
+ $current_template = gutenberg_find_template_post_and_parts( $type, $templates );
if ( $current_template ) {
$_wp_current_template_id = $current_template['template_post']->ID;
diff --git a/lib/templates.php b/lib/templates.php
index 9336cf44717cf..62bea3fb39642 100644
--- a/lib/templates.php
+++ b/lib/templates.php
@@ -183,7 +183,7 @@ function filter_rest_wp_template_collection_params( $query_params ) {
function filter_rest_wp_template_query( $args, $request ) {
if ( $request['resolved'] ) {
$template_ids = array( 0 ); // Return nothing by default (the 0 is needed for `post__in`).
- $template_types = $request['slug'] ? array( $request['slug'] ) : get_template_types();
+ $template_types = $request['slug'] ? $request['slug'] : get_template_types();
foreach ( $template_types as $template_type ) {
// Skip 'embed' for now because it is not a regular template type.
@@ -194,10 +194,10 @@ function filter_rest_wp_template_query( $args, $request ) {
$current_template = gutenberg_find_template_post_and_parts( $template_type );
if ( isset( $current_template ) ) {
- $template_ids[ $current_template['template_post']->post_name ] = $current_template['template_post']->ID;
+ $template_ids[] = $current_template['template_post']->ID;
}
}
- $args['post__in'] = array_values( $template_ids );
+ $args['post__in'] = $template_ids;
}
return $args;
diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js
index 3bcfbcda55740..702e1f3f6bfc3 100644
--- a/packages/edit-site/src/components/block-editor/index.js
+++ b/packages/edit-site/src/components/block-editor/index.js
@@ -74,16 +74,11 @@ export default function BlockEditor() {
( fillProps ) => (
),
- [
- settings.templateIds,
- settings.templateId,
- setActiveTemplateId,
- ]
+ [ settings.templateId, setActiveTemplateId ]
) }
diff --git a/packages/edit-site/src/components/navigate-to-link/index.js b/packages/edit-site/src/components/navigate-to-link/index.js
index 2b4e018bab1b5..ece3c36db4b99 100644
--- a/packages/edit-site/src/components/navigate-to-link/index.js
+++ b/packages/edit-site/src/components/navigate-to-link/index.js
@@ -12,12 +12,7 @@ import { __ } from '@wordpress/i18n';
*/
const { fetch } = window;
-export default function NavigateToLink( {
- url,
- templateIds,
- activeId,
- onActiveIdChange,
-} ) {
+export default function NavigateToLink( { url, activeId, onActiveIdChange } ) {
const [ templateId, setTemplateId ] = useState();
useEffect( () => {
const effect = async () => {
@@ -28,14 +23,15 @@ export default function NavigateToLink( {
if ( success ) {
let newTemplateId = data.ID;
if ( newTemplateId === null ) {
- const { getEntityRecord } = select( 'core' );
- newTemplateId = templateIds
- .map( ( id ) =>
- getEntityRecord( 'postType', 'wp_template', id )
- )
- .find(
- ( template ) => template.slug === data.post_name
- ).id;
+ const { getEntityRecords } = select( 'core' );
+ newTemplateId = getEntityRecords(
+ 'postType',
+ 'wp_template',
+ {
+ resolved: true,
+ slug: data.post_name,
+ }
+ )[ 0 ].id;
}
setTemplateId( newTemplateId );
} else {
@@ -46,7 +42,7 @@ export default function NavigateToLink( {
}
};
effect();
- }, [ url, templateIds ] );
+ }, [ url ] );
const onClick = useMemo( () => {
if ( ! templateId || templateId === activeId ) {
return null;