Discover in this tutorial all the options offered by the query loop block and learn how to customize it.
WordPress 5.8 introduced the query block. At the beginning it had some limitations, for example, it didn’t allow to list Custom Post Types entries, but in the last WordPress updates it has improved a lot.
So I think it is worth reviewing all the options offered in the user interface and learning which are the ones you can extend with a little bit of code.
To do this let’s see the available settings both at the design and query level.
Design options for the query loop block
On the one hand, you can customize the layout. Starting from a block pattern (if the theme you are using includes it) or creating it from scratch to your liking.
These are the elements you can control:
- Show/hide featured image.
- Show/hide the date.
- Show/hide the excerpt.
- Customize the “Read more” text.
- Choose the grid layout.
- Choose the number of columns for the grid layout.
- Choose the HTML markup for the title (H2, H3 or H4).
- Show/hide/edit pagination.
- Edit the content displayed if there is no entry that meets the query criteria.
Since all elements are blocks, you can move and modify them as you like.
And you can take the customization one step further by creating a block variation.
Query options for the query loop block
On the other hand, you can modify the query parameters. The settings that are available from the user interface are:
- The type of content (including CPTs)
- Sort by:
- From newest to oldest
- Oldest to newest
- A to Z (by title)
- Z to A (by title)
- Fixed entries
- Include
- Exclude
- Only
- Filters
- Taxonomies (only in posts)
- Keywords
- Authors
- Choose parent content (only in hierarchical content types)
- Number of entries
- Offset
- Maximum pages to display
As you can see in the image above, most of the settings are located in the right sidebar. But some extra settings are located in the block toolbar:
The user interface offers quite a few options, but it is far from reaching the granularity you can get by modifying WP_Query
.
The good thing is that thanks to a PHP filter introduced in WordPress 6.1 you can modify the query beyond what the interface allows you to do.
For example, you can combine the entries of several CPTs in the same content listing.
Conclusions
The content listing block is a very powerful tool and it is worth spending a little time to take advantage of it.
For example, you can easily create archive pages in both classic themes and block themes (FSE).
Now that you know it a little better, in the next tutorials I will explain how you can use a filter to expand the possibilities almost to infinity (everything that WP_Query
allows, which is not little).
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂