Skip to content

Commit 729b857

Browse files
ryanwelcherCopilot
andauthored
Update src/variations/controls.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent baf5cb4 commit 729b857

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/variations/controls.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,22 @@ const isAdvancedQueryLoop = ( props ) => {
5252
* @return {Element} BlockEdit instance
5353
*/
5454
const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => {
55-
const { currentPostId, currentPostType } = useSelect( ( select ) => {
56-
const editor = select( editorStore );
57-
return {
58-
currentPostId: editor.getCurrentPostId(),
59-
currentPostType: editor.getCurrentPostType(),
60-
};
61-
} );
55+
const { currentPostId, currentPostType } = useSelect(
56+
( select ) => {
57+
if ( ! isAdvancedQueryLoop( props ) ) {
58+
return {
59+
currentPostId: undefined,
60+
currentPostType: undefined,
61+
};
62+
}
63+
const editor = select( editorStore );
64+
return {
65+
currentPostId: editor.getCurrentPostId(),
66+
currentPostType: editor.getCurrentPostType(),
67+
};
68+
},
69+
[ props?.attributes?.namespace ]
70+
);
6271

6372
// If the is the correct variation, add the custom controls.
6473
if ( isAdvancedQueryLoop( props ) ) {

0 commit comments

Comments
 (0)