GenerateBlocks 2.0 is here - Read the release post

Learn GenerateBlocks

Query

Description

The Query block can dynamically display content from your WordPress Database. It supports the following query types:

  • Post Query
    a list of posts, pages or custom post types
  • Post Meta Query ( Pro )
    data stored in a post meta array in your database
  • Option Query ( Pro )
    data stored in the options table

Additional Query Types such as Term Queries will be coming in future updates.

Block Structure

The Query Block consists of 3 proprietary blocks; Query, Looper and Loop Item. With optional blocks for displaying Pagination and No results:

  • Query
  • Looper
  • Loop Item
  • Container ( for pagination )
  • Previous
  • Page Numbers
  • Next
  • No Results
  • No Results Found

Query Block

The Query Block is where the real work gets done. This block is responsible for building the query and returning the queried data for consumption by its inner blocks.

Looper

The Looper rather simply loops over the data passed to it from the parent Query and for each iteration it will output a Loop Item. This block is the grouping block for all the Loop items and has the same block settings as a basic Grid Block. It is here where you can set the query to display in a list or as a more complex grid layout.

See Grid Block for more settings.

Loop Item

The Loop Item is where the content gets output. Any blocks placed inside the Query Item will be output for each iteration of the loop. The blocks added within the Loop Item will be, primary, built with Dynamic Tags. The Loop Item block has the same settings as a basic Container Block,

See Container Block for more settings.

Toolbar

The Query block has the following toolbar options.

The toolbar for the Query block
Add the selected blocks inside a new Container Block
This action will insert the Pagination Blocks to the currently selected Query Block.The Pagination consists of a Container Block and 3 x Button blocks for the Previous Page, Next Page and Paged Links. List view example: Container Previous Page Numbers Next
This action adds a No Results notice to the currently selected Query Loop Block.The notice consists of a no results Container and Text Blocks. These blocks will only be output if the attached Query returns no results. List View No Results No Results Found

Block Settings

The Query Block settings is where the query is created. The settings available in the block vary depending on the Query type that is selected. By default the Query Type is the Post Query. Other Query Types are available in GenerateBlocks Pro and include Post Meta and Options.

We will cover each Query Type separately in its own section below.

Tag Name – all query types

Choose the blocks HTML Element tag:

  • div
  • section
  • article
  • aside
  • header
  • footer
  • nav
  • main

Query Type: Post Query

The default query type of Post Query will allow you to query and display Posts.

Pagination Type

If the Query Block is to show a lot of posts it may be necessary to add Pagination to the Query. Thos can be added via the blocks toolbar. This block setting allows you to define loading behaviour of the Pagination:

  • Standard – the standard pagination that will reload the page on each link.
  • Instant – load the posts instantly without the need for page reload

Inherit Query from Template

This option should be used when building custom theme templates, such as the Blog ( Index ), Archive or Search Results.

Checking this option tells the query block to ignore any of the block setting parameters and instead inherit the query from the current template. Modifying an inherited query requires PHP to modify the wp_query before it gets run. This can be achieved using the core pre_get_posts filter hook:

Select Post Type

Choose which Post Types to include in the query. The user can choose single or multiple post types to be included. Post Types include Posts & Pages and any Custom Post Types.

Custom Post not displaying in the list?

Read here as to why a post type does not show in the Post Type options list.

Posts per page

Set how many posts to display for each page. If you need to display posts in pages then you can add a Pagination block via the blocks Toolbars.

When using Inherit Query from Template, the posts per page will be set in the Dashboard > Settings > Reading -> Blog Post Show at Most setting.

Add Parameter

With the Add Parameter button you add additional args to the Query. All of arguments follow the WordPress codex specification for wp_query

Parameters

Pagination

  • Page – Display posts from a select page of the query pagination.
  • Offset – Offset the query results by a specific number of items.

Search

  • Search – shows posts that match the given keyword search .

Order & Order by

  • Order – Designates the ascending or descending order of the ‘orderby‘ parameter.
  • Orderby – Sort retrieved posts by parameter.

Authors

  • Authors – Show posts from authors. Search by name or ID.
  • Exclude Authors – Exclude posts from authors. Search by name or ID.

Taxonomiies

  • Taxonomy – choose from the available taxonomies and the specific terms to filter the query by.

Multiple taxonomies are treated as a OR relationship.

Post Status

  • Status – Show posts by post status.

Post

  • Parent – Show posts from parents. Search by name or ID.
  • Exclude Parent – exclude posts from parents. Search by name or ID.
  • Include Posts – Limit result set to specific posts. Search by name or ID.
  • Exclude Posts – Ensure result set excludes specific posts. Search by name or ID.
  • Sticky Posts – Configure how sticky posts should show in the query.

Date

  • Date – Limit response to posts published before and after a given date.

Query Type: Post Meta

The Post Meta Query Type allows you to output data stored in the Post Meta. Data arrays in post meta are often used to store ranges of data or relationships, such as Relationship or Repeater fields added by plugins like ACF ( Advanced Custom Fields ).

Pagination Type

This block setting allows you to define loading behaviour of the Pagination:

  • Standard – the standard pagination that will reload the page on each link.
  • Instant – load the posts instantly without the need for page reload

Select Post

Select the source post to retrieve the post meta from. you can choose from the current post ( default ) or select a specific post.

Meta Key

Choose the Meta Key from which to retrieve the data. Note: it must be an array.

Meta Key not displaying in the list?

Make sure the Post Meta Key has REST API support.
Alternatively you can manually enter the value , but you may only see the results on the front end.

Per page

Set how many post meta item to display for each page. You can add a Pagination block via the blocks Toolbars.

Offset

Displace ( skip over ) a number of post meta items in the returned results.

Query Type: Option

The Option Query Type allows you to output data stored in the Options table.

Pagination Type

This block setting allows you to define loading behaviour of the Pagination:

  • Standard – the standard pagination that will reload the page on each link.
  • Instant – load the posts instantly without the need for page reload

Meta Key

Choose the Meta Key from which to retrieve the data. Note: it must be an array.

Meta Key not displaying in the list?

Make sure the Post Meta Key has REST API support.
Alternatively you can manually enter the value , but you may only see the results on the front end.

Per page

Set how many post meta item to display for each page. You can add a Pagination block via the blocks Toolbars.

Offset

Displace ( skip over ) a number of post meta items in the returned results.