Hello ColinD,
You’re absolutely correct—when the Query Loop Block is set to inherit its query from the template, the query_loop_block_query_vars
filter does not run. This is because, in inherit mode, the block uses the main query ($wp_query
) that’s already been established by WordPress, rather than creating a new custom query. As a result, the filter designed to modify the Query Loop Block’s custom queries isn’t applied.
The pre_get_posts
hook allows you to modify the main query parameters before it’s executed, which will, in turn, affect any blocks or templates relying on that query—including the Query Loop Block set to inherit. It is the recommended and widely accepted method for modifying queries before they are executed.
Ensure you include the necessary conditional checks (! is_admin()
, $query->is_main_query()
, is_archive()
, is_category()
, is_post_type_archive()
etc.) to target only the queries you want to modify. This prevents unintended effects on other queries.
I hope this clarifies your doubt and helps you make an informed decision. If you have further questions or need assistance feel free to ask!