@@ -5,11 +5,12 @@ import {
55 TextControl ,
66 SelectControl ,
77 RangeControl ,
8- __experimentalToggleGroupControl as ToggleGroupControl ,
9- __experimentalToggleGroupControlOption as ToggleGroupControlOption ,
108 Notice ,
9+ __experimentalVStack as VStack ,
1110 __experimentalToolsPanel as ToolsPanel ,
1211 __experimentalToolsPanelItem as ToolsPanelItem ,
12+ __experimentalToggleGroupControl as ToggleGroupControl ,
13+ __experimentalToggleGroupControlOption as ToggleGroupControlOption ,
1314} from '@wordpress/components' ;
1415import { useSelect } from '@wordpress/data' ;
1516import { store as coreStore } from '@wordpress/core-data' ;
@@ -113,8 +114,7 @@ export default function QueryInspectorControls( props ) {
113114 } , [ querySearch , onChangeDebounced ] ) ;
114115
115116 const orderByOptions = useOrderByOptions ( postType ) ;
116- const showInheritControl =
117- ! isSingular && isControlAllowed ( allowedControls , 'inherit' ) ;
117+ const showInheritControl = isControlAllowed ( allowedControls , 'inherit' ) ;
118118 const showPostTypeControl =
119119 ! inherit && isControlAllowed ( allowedControls , 'postType' ) ;
120120 const postTypeControlLabel = __ ( 'Post type' ) ;
@@ -185,6 +185,10 @@ export default function QueryInspectorControls( props ) {
185185 const showDisplayPanel =
186186 showPostCountControl || showOffSetControl || showPagesControl ;
187187
188+ // The block cannot inherit a default WordPress query in singular content (e.g., post, page, 404, blank).
189+ // Warn users but still permit this type of query for exceptional cases in Classic and Hybrid themes.
190+ const hasInheritanceWarning = isSingular && inherit ;
191+
188192 return (
189193 < >
190194 { showSettingsPanel && (
@@ -208,36 +212,48 @@ export default function QueryInspectorControls( props ) {
208212 onDeselect = { ( ) => setQuery ( { inherit : true } ) }
209213 isShownByDefault
210214 >
211- < ToggleGroupControl
212- __next40pxDefaultSize
213- __nextHasNoMarginBottom
214- label = { __ ( 'Query type' ) }
215- isBlock
216- onChange = { ( value ) => {
217- setQuery ( {
218- inherit : value === 'default' ,
219- } ) ;
220- } }
221- help = {
222- inherit
223- ? __ (
224- 'Display a list of posts or custom post types based on the current template.'
225- )
226- : __ (
227- 'Display a list of posts or custom post types based on specific criteria.'
228- )
229- }
230- value = { ! ! inherit ? 'default' : 'custom' }
231- >
232- < ToggleGroupControlOption
233- value = "default"
234- label = { __ ( 'Default' ) }
235- />
236- < ToggleGroupControlOption
237- value = "custom"
238- label = { __ ( 'Custom' ) }
239- />
240- </ ToggleGroupControl >
215+ < VStack spacing = { 4 } >
216+ < ToggleGroupControl
217+ __next40pxDefaultSize
218+ __nextHasNoMarginBottom
219+ label = { __ ( 'Query type' ) }
220+ isBlock
221+ onChange = { ( value ) => {
222+ setQuery ( {
223+ inherit : value === 'default' ,
224+ } ) ;
225+ } }
226+ help = {
227+ inherit
228+ ? __ (
229+ 'Display a list of posts or custom post types based on the current template.'
230+ )
231+ : __ (
232+ 'Display a list of posts or custom post types based on specific criteria.'
233+ )
234+ }
235+ value = { ! ! inherit ? 'default' : 'custom' }
236+ >
237+ < ToggleGroupControlOption
238+ value = "default"
239+ label = { __ ( 'Default' ) }
240+ />
241+ < ToggleGroupControlOption
242+ value = "custom"
243+ label = { __ ( 'Custom' ) }
244+ />
245+ </ ToggleGroupControl >
246+ { hasInheritanceWarning && (
247+ < Notice
248+ status = "warning"
249+ isDismissible = { false }
250+ >
251+ { __ (
252+ 'Cannot inherit the current template query when placed inside the singular content (e.g., post, page, 404, blank).'
253+ ) }
254+ </ Notice >
255+ ) }
256+ </ VStack >
241257 </ ToolsPanelItem >
242258 ) }
243259
0 commit comments