diff --git a/packages/block-library/src/query/edit/inspector-controls/index.js b/packages/block-library/src/query/edit/inspector-controls/index.js index cf0b80b6145632..66ba962a074608 100644 --- a/packages/block-library/src/query/edit/inspector-controls/index.js +++ b/packages/block-library/src/query/edit/inspector-controls/index.js @@ -5,11 +5,12 @@ import { TextControl, SelectControl, RangeControl, - __experimentalToggleGroupControl as ToggleGroupControl, - __experimentalToggleGroupControlOption as ToggleGroupControlOption, Notice, + __experimentalVStack as VStack, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, + __experimentalToggleGroupControl as ToggleGroupControl, + __experimentalToggleGroupControlOption as ToggleGroupControlOption, } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; @@ -113,8 +114,7 @@ export default function QueryInspectorControls( props ) { }, [ querySearch, onChangeDebounced ] ); const orderByOptions = useOrderByOptions( postType ); - const showInheritControl = - ! isSingular && isControlAllowed( allowedControls, 'inherit' ); + const showInheritControl = isControlAllowed( allowedControls, 'inherit' ); const showPostTypeControl = ! inherit && isControlAllowed( allowedControls, 'postType' ); const postTypeControlLabel = __( 'Post type' ); @@ -185,6 +185,10 @@ export default function QueryInspectorControls( props ) { const showDisplayPanel = showPostCountControl || showOffSetControl || showPagesControl; + // The block cannot inherit a default WordPress query in singular content (e.g., post, page, 404, blank). + // Warn users but still permit this type of query for exceptional cases in Classic and Hybrid themes. + const hasInheritanceWarning = isSingular && inherit; + return ( <> { showSettingsPanel && ( @@ -208,36 +212,48 @@ export default function QueryInspectorControls( props ) { onDeselect={ () => setQuery( { inherit: true } ) } isShownByDefault > - { - setQuery( { - inherit: value === 'default', - } ); - } } - help={ - inherit - ? __( - 'Display a list of posts or custom post types based on the current template.' - ) - : __( - 'Display a list of posts or custom post types based on specific criteria.' - ) - } - value={ !! inherit ? 'default' : 'custom' } - > - - - + + { + setQuery( { + inherit: value === 'default', + } ); + } } + help={ + inherit + ? __( + 'Display a list of posts or custom post types based on the current template.' + ) + : __( + 'Display a list of posts or custom post types based on specific criteria.' + ) + } + value={ !! inherit ? 'default' : 'custom' } + > + + + + { hasInheritanceWarning && ( + + { __( + 'Cannot inherit the current template query when placed inside the singular content (e.g., post, page, 404, blank).' + ) } + + ) } + ) } diff --git a/packages/block-library/src/query/edit/query-content.js b/packages/block-library/src/query/edit/query-content.js index 55a2b24cfd1a51..dc4edd16d849ee 100644 --- a/packages/block-library/src/query/edit/query-content.js +++ b/packages/block-library/src/query/edit/query-content.js @@ -101,21 +101,15 @@ export default function QueryContent( { } else if ( ! query.perPage && postsPerPage ) { newQuery.perPage = postsPerPage; } - // We need to reset the `inherit` value if in a singular template, as queries - // are not inherited when in singular content (e.g. post, page, 404, blank). - if ( isSingular && query.inherit ) { - newQuery.inherit = false; - } + if ( !! Object.keys( newQuery ).length ) { __unstableMarkNextChangeAsNotPersistent(); updateQuery( newQuery ); } }, [ query.perPage, - query.inherit, - postsPerPage, inherit, - isSingular, + postsPerPage, __unstableMarkNextChangeAsNotPersistent, updateQuery, ] );