-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Labels
[Block] Query LoopAffects the Query Loop BlockAffects the Query Loop Block[Type] EnhancementA suggestion for improvement.A suggestion for improvement.
Description
Description
The is_main_query() conditional function should return false if running inside an external query loop block.
Step-by-step reproduction instructions
Add the following code to your function, then add a query block to your theme outside the post content.
function main_query_show_warning( $block_content, $block ) {
if ( is_main_query() ) {
$warning = sprintf(
'<div style="font-size: 14px; background: red; color: #fff; padding: 2px 6px; font-weight: 700; display: inline-block;">%s</div>',
__( 'this is a main query' ),
);
$block_content = $warning . $block_content;
}
return $block_content;
}
add_filter( 'render_block_core/query', 'main_query_show_warning', 10, 2 );
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[Block] Query LoopAffects the Query Loop BlockAffects the Query Loop Block[Type] EnhancementA suggestion for improvement.A suggestion for improvement.