Core Editor Improvement: Simplified Query Loop block with smarter defaults & intuitive settings

These “CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. Editor Improvement…” posts (labeled with the #core-editor-improvement tagtag A directory in Subversion. WordPress uses tags to store a single snapshot of a version (3.6, 3.6.1, etc.), the common convention of tags in version control systems. (Not to be confused with post tags.)) are a series dedicated to highlighting various new features, improvements, and more from Core Editor related projects. 

In the spirit of Matt’s “simple things should be easy and intuitive, and complex things possible”, the Query LoopLoop The Loop is PHP code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page, and formats it according to how it matches specified criteria within The Loop tags. Any HTML or PHP code in the Loop will be processed on each post. https://codex.wordpress.org/The_Loop. blockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. has been refreshed with a focus on ensuring the most intuitive default state possible out of the box and increased clarity when trying to achieve anything more complex with custom queries. All of what’s shared below is slated for inclusion in the upcoming WordPress 6.7 release on November 12th, 2024

Strong defaults

With recent updates, you no longer need to manually enable “Inherit query from template.” The Query Loop block now automatically inherits the query by default, ensuring expected posts are displayed both in the editor and on the front end. This change simplifies the process for most users, who typically just want to see their posts appear without complications. It also minimizes the likelihood of confusion, such as when a Query Loop block is added but posts don’t show up. Now, whenever you add a Query Loop block—whether starting from scratch or using a pattern—your posts will display immediately. This includes when adding a Query loop block to single post or page where the settings will automatically be configured to work in that context. Additionally, the Post List variation has been removed from the Inserter, as its default settings often caused posts to not display, leading to a confusing user experience.

Added clarity

To make this complex block more user-friendly and predictable, the settings have been simplified. Now, there’s a toggle to choose between using the default options or creating a custom query. If you select a custom query, another toggle lets you choose between posts or pages, with the usual filtering options. For custom post types, this section becomes a dropdown for easier selection. In response to feedback about scattered settings for the Query Loop block, options for Posts Per Page, Offset, and Max Pages to Show have been moved to the Settings panel. This change makes the settings sidebarSidebar A sidebar in WordPress is referred to a widget-ready area used by WordPress themes to display information that is not a part of the main content. It is not always a vertical column on the side. It can be a horizontal rectangle below or above the content area, footer, header, or any where in the theme. the central place to configure the Query Loop block fully.

Refined details

The details matter, and these refinements are no exception: a preview now appears when selecting the Query Loop block, and the “Add a new post” prompt now reflects the specific type of content you’re querying. The help text for sticky posts has been updated to clarify that sticky posts will always appear first. Additionally, the enhanced pagination setting has been moved to the Advanced section with a new label for better clarity.

Post format support

To help take steps towards post formats in Block themes, the Query Loop block has a new parameter called “format” that allows you to filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. the content shown by post format, in the same way you’d filter by any other option. This additional filter can be combined with others so you can create custom queries for something as nuanced as posts by a specific author across two categories and with a certain post format. 

Query Loop block filter settings showing Categories, Tags, and Author with the "Formats" option highlighted for emphasis.

#core-editor-improvement, #query-loop