The Query Loop block allows you to display posts based on specified parameters; like a PHP loop without the code.
It uses all of the core blocks that you are already familiar with. You can display the posts in columns (or not) with our Grid block, and display all of the post data (titles, dates, excerpts) with the Headline and Button blocks.
Inserting a Query Loop Block
First, make sure you’ve already added a Container Block. It’s good practice to wrap your query loop in a surrounding Container, as it gives you more options moving forward.
Once you choose the Query Loop Block in the editor, you’ll be given a choice of layout presets.
The query parameters allow you to customize further what posts are being displayed.
Inherit query from template
This option allows the query loop to get the query from the default template. It’s usually used when the query loop is in a block element – loop template of GeneratePress theme, or in the archive template of an FSE.
For example, with this option toggled:
- if it’s on the blog page, it will get all the published posts.
- if the query loop is on a category archive page, it will get all the posts that are assigned to this category.
- if it’s on a custom-post-type archive, it will get all the published custom posts.
It inherits the posts per page from your posts per page settings at WP dashboard > settings > reading.
Select post type
This list shows all the registered post types. The common types include page, post, product (if using WooCommerce), and your custom post types.
Posts per page
Set the numbers of posts per page for this block.
Add additional parameters to further customize the posts displayed in this block.
See full detailed explanations on the WP_Query page.
Clicking the Layout panel selects the Grid block that is positioned under the Query loop block. It allows you to configure the column settings if needed and the options are exactly the same as in the Grid block.
To add pagination to the Query Loop block, simply click on the + icon in the top/floating toolbar.
The default pagination buttons come with GB button’s default style, you can customize it after it’s been added.