diff --git a/packages/block-library/src/query/block.json b/packages/block-library/src/query/block.json index 302ea1a8e80856..81a963574c7fa4 100644 --- a/packages/block-library/src/query/block.json +++ b/packages/block-library/src/query/block.json @@ -37,7 +37,8 @@ "layout": "layout" }, "usesContext": [ - "postId" + "postId", + "templateSlug" ], "supports": { "html": false diff --git a/packages/block-library/src/query/edit/index.js b/packages/block-library/src/query/edit/index.js index 45be4c7f88537c..9cbe8fc1ee375e 100644 --- a/packages/block-library/src/query/edit/index.js +++ b/packages/block-library/src/query/edit/index.js @@ -22,7 +22,7 @@ import { DEFAULTS_POSTS_PER_PAGE } from '../constants'; const TEMPLATE = [ [ 'core/query-loop' ] ]; export function QueryContent( { attributes, - context: { postId }, + context: { postId, templateSlug }, setAttributes, } ) { const { queryId, query, layout } = attributes; @@ -47,10 +47,15 @@ export function QueryContent( { if ( ! query.perPage && postsPerPage ) { newQuery.perPage = postsPerPage; } + // Show and allow inherit Query options only when + // in site-editing context. + if ( ! templateSlug && query.inherit ) { + newQuery.inherit = false; + } if ( !! Object.keys( newQuery ).length ) { updateQuery( newQuery ); } - }, [ query.perPage, query.exclude, postId ] ); + }, [ query.perPage, query.exclude, query.inherit, postId, templateSlug ] ); // We need this for multi-query block pagination. // Query parameters for each block are scoped to their ID. useEffect( () => { @@ -68,6 +73,7 @@ export function QueryContent( { attributes={ attributes } setQuery={ updateQuery } setLayout={ updateLayout } + allowInheritQuery={ !! templateSlug } /> - setQuery( { inherit: !! value } ) } - /> + { allowInheritQuery && ( + + setQuery( { inherit: !! value } ) + } + /> + ) } { ! inherit && (