WordPress.org

WordPress Developer Blog

Building a book review grid with a Query Loop block variation

WordPress 6.1 introduced new methods for extending the Query Loop block.  This is a significant milestone because it puts a lot of functionality in the hands of plugin developers at little cost, at least in terms of code. Instead of building custom blocks to query posts, extenders need to only filter the existing functionality in core WordPress.

The Query Loop block is a workhorse in building websites out of blocks.  It is the foundation for displaying content from posts, pages, and other custom post types (CPTs).

Before WordPress 6.1, its primary use case was displaying a limited subset of what was previously possible when compared to its PHP counterpart: WP_Query.  This meant that developers, particularly when handling data for CPTs, were often building entire custom blocks on their own.

Today, extenders can build atop a solid foundation for outputting nearly any type of content with minimal code on their part.  The changes in version 6.1 allow plugin authors to skip the block development aspect and extend the built-in Query Loop block.

A few examples of the ways this can be used include:

  • Displaying a grid of products by a price meta field.
  • Business directory listing businesses by location.
  • Leaderboard for a peer-to-peer fundraiser.
  • Outputting book reviews by rating.

For this walk-through, you will learn how to tackle the last item in that list: listing book review posts. You will build a WordPress plugin from start to finish.  The result will be a Query Loop block variation that looks similar to the following screenshot: