A Query Loop’s editor settings select a post type. To combine multiple public post types on the front end, use the documented query_loop_block_query_vars filter and scope it to one Post Template block.

This filter changes the query created by the Query Loop itself. A main-query-only pre_get_posts callback will not reliably target an independent Query Loop.
Here is a step-by-step guide:
Step 1: Mark the Post Template block
- Open the page or post where you want to add the Query Loop block in the Block Editor.
- Select the Post Template block inside your Query Loop.
- In the block settings on the right-hand side, expand the “Advanced” panel.
- Add a custom class name, for example, custom-query-loop, to the “Additional CSS class(es)” field.
Step 2: Filter this Query Loop
Add the following code to a site-specific plugin or your child theme. Replace book with an existing public custom post type.
add_filter('query_loop_block_query_vars', function ($query, $block) {
$classes = preg_split('/\s+/', $block->parsed_block['attrs']['className'] ?? '');
if (!in_array('custom-query-loop', $classes, true)) {
return $query;
}
$query['post_type'] = ['post', 'book'];
return $query;
}, 10, 2);
Explanation
- Filter the Query Loop arguments:
- The filter receives the Query Loop arguments and the marked Post Template block.
- It checks the Post Template class before changing the post_type argument.
- Scope the block:
- The class identifies this block only; the main query does not need a custom variable.
- Use the documented block query filter instead of passing a variable to the main query.
Step 3: Ensure Query Loop Block Renders Correctly
Use a custom query rather than an inherited archive query. The front-end filter does not change the editor’s REST preview; an editor variation requires its own REST-compatible query support.
Additional Note
Only the marked Post Template is affected. Keep the other Query Loops unmarked, test their results and check pagination with each selected post type.
Want to add filter and search to your Query Loop Block too?
Read our tutorial on using the Filter Query Block Pro plugin to easily add filters and search to your Query Loop block!
Frontend and editor previews
The query filter applies to frontend rendering. WordPress’s extension guide explains the separate REST-based editor preview. Verify the published page and pagination rather than expecting the editor preview to show the modified query.



