Help Center
JetEngine’s Query Builder and Query Generators Explained
Useful Resources

JetEngine’s Query Builder and Query Generators Explained

ivanova
Helena Ivanova
|
Technical content writer
Show all articles

The great thing about WordPress is that it is not only highly user-friendly but also very powerful. One example of WordPress’s power and versatility in action is the WP_Query class. It manipulates posts, but there are other classes that work with users, comments, terms, and so on. 

In this article, I will briefly explain what the WP_Query does, how to use it with the help of a query generator, and introduce the very powerful tool that can work not only with WP_Query but with other classes – in simple terms, fetch any data from the website database according to your parameters, and help you display it on the front end without a line of coding or complex manipulations. 

What Is WordPress Query?

As one of the most important aspects of the WordPress codebase, the WP_Query class enables the safe and simple execution of complex database queries. It determines the query for a particular page and pulls the necessary posts.

WordPress Query Use Cases

The WordPress Query can be used for so many things. The first example below is a WP_Query for fetching posts from the music category:

$the_query = new WP_Query([

    'category_name' => 'music',
]);

However, that code on its own will not display the posts. To do just that, we need to use the WordPress loop. For example:

<?php
// The Query
$the_query = new WP_Query( 'category_name=music' );
// The Loop
if ( $the_query->have_posts() ) {
        echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
        echo '</ul>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>

In this next example, WP_Query is used for fetching a list of all the posts written by a particular author this year:

<?php
	 
// Get the year we're in.
$current_year = date( 'Y' );
	 
// Setup arguments.
$args = array(
    // Get the author with the nickname "dave".
    'author_name' => dave,
    // Get his posts from this year.
    'year'   => $current_year
);
 
// Instantiate new query instance.
$my_query = new WP_Query( $args );
	 
?>

These examples only scratch the surface of what WP_Query. It is a powerful tool for writing advanced and complex queries. You can use it to create loops within loops, known as nested loops. WordPress developers use it in themes and plugins for displaying posts.

The WordPress Codex contains a complete list of WP_Query parameters.

WordPress Query Generator

Working with custom WordPress queries can be challenging, especially if you’re new to coding or PHP and need to implement multiple query methods for your post types.

A Crocoblock subscription offers various widgets for displaying custom post types, including the Listing Grid widget in JetEngine, Smart Posts Tiles and Smart Posts List in JetBlog, and the Posts widget in JetElements.

While the Listing Grid widget includes its own powerful query builder with advanced methods, JetBlog and JetElements widgets rely on the default WordPress query and don’t support custom query types out of the box.

To bridge this gap, first, the Crocoblock team has created a free WP Query Generator tool. It allows you to generate custom PHP query code that can be applied to your dynamic post feeds.

Later on, it was transformed into the powerful Query Builder tool with a fully visual UI. However, let me demonstrate how the WP Query Generator works to help you understand which parameter it deals with. 

How the WP Query Generator works

The WordPress Query generator is divided into sections dedicated to different query parameters. When you set them, they become automatically added to the Generated Query code. The more parameters you use, the longer and more complex it becomes.

wp query generator tool for wordpress

When you use “meta” or “tax_query”, you can add several parameters and set the relation applied to query the posts.

Once everything is done, you will have two options for using the code in the generated Query block.

JSON

Use the JSON option to generate the query in JSON format for JetPlugins widgets. Click “Copy to Clipboard” to save the code.

In Elementor, edit one of the Crocoblock widgets that display posts (Smart Posts List, Smart Posts Tiles, or Posts). Navigate to Content > General, find the Custom Query block, and enable the Use Custom Query option.

Paste the generated code into the Set custom query field — the widget will automatically pull posts based on the defined parameters.

PHP

wp_query pagination settings

Use PHP to retrieve the query arguments array and utilize it in your work whenever you add a WP Query to PHP.

To use the generated arguments array, click the “Copy to Clipboard” button and paste the code to the relevant PHP template file.

Setting General Parameters

When you open the WP Query Generator tool, you will be redirected to the General Parameters section. Here you will be able to set:

  • Post type – here, you will need to enter the post type slug, such as ‘post’, ‘service’, etc.
  • Post status – click on the field to select the status to query the posts using it (e.g., publish, draft, etc.).
  • Order – choose ASC or DESC value to sort the posts in ascending or descending order.
  • Orderby – here, you can choose the parameter that will be used to set the post order (e.g., select the date parameter and ACS order to show the posts in the order of oldest to newest).

Pagination parameters

wp_query pagination settings
  • Posts per page – type in the number of posts you want to be displayed per page (e.g., “5” to display only five posts from all the queried posts).
  • Offset – use this parameter to hide some of the posts already displayed (e.g., one will hide the first post from the query from being shown).
  • Paged – here, you have to define the page number where you want to show the posts (in case you want them to be displayed on this particular page).
  • Page – here, you can set the page number to be displayed on the static front page.
  • Ignore sticky posts – enable this option to let the query work without considering the posts set as sticky.

Post and page parameters

post and page wp query settings

You can pull specific posts in this section using their ID, slug, and title. You will also be able to exclude or include pages using IDs, slugs, or retrieve a page in which its parent is in the list or not.

There are also fields where you can add information on the post IDs to identify the posts you want to retrieve.

Author parameters

author settings

Here, you can define the author by ID or name to pull the posts published by one or several authors.

Category and tag parameters

tag and category settings

In this section, you can include the query posts from the specific categories or tags (using category ID or slug) or exclude posts by category ID, slug, or specific tag.

For example, to retrieve posts related to the Essays category but exclude those with the Non-fiction category, you will have to add the ID of the Essays category in the Category In field and add the Non-fiction category ID in the Category, not in the field.

In this case, you will only get the posts that are included in the Essays category and don’t fall under the Non-fiction category at the same time (the posts that are categorized as Essays and Non-fiction at the same time will be excluded).

Taxonomy query parameters

taxonomy query settings

This section allows you to use custom taxonomy terms to query posts. Here you can add several taxonomy types and use the specific taxonomy terms to retrieve the required posts or exclude the ones you don’t want to be displayed.

Each taxonomy query (or tax_query) has a set of operators (IN, NOT IN, AND, EXISTS, NOT EXISTS) to define whether the posts with specific terms should be included or excluded.

When you add more than one tax_query, you can also select the relation between the queries:

  • AND – use this to query the posts that satisfy all the set taxonomy queries.
  • OR – use this to query the posts that satisfy at least one of the queries.

Meta parameters

meta query settings

In this section, you can use several meta keys and query posts by meta fundamental values (this option is particularly useful for product post types and prices).

  1. To create a new meta_query, you have to add an ID for the meta field (also called a custom field) or get it from the database, and then input the value to use in the query method.
  2. In the Compare block, you will have a set of available operators that allow you to query posts with values in the defined custom field that are equal to, less than, or greater than the set value, etc. For example, you can query products whose prices are higher than or equal to $5 and exclude all the rest.
  3. If you add several meta query parameters, you can define their relationships using AND and OR operators (they work the same as in tax_query).

There are also Date and Misc parameters to refine the query even better. 

But have you noticed one major drawback of using the Query Generator? You still have to look up and insert all the parameters manually. A single typo, and the query won’t work. On top of that, finding the right IDs, slugs, category names, and other elements can be time-consuming. And once you’ve built the query, you still need to insert it into the right place to make it work.

A decade ago, editing PHP templates to display different posts was standard practice. Today, with modern visual builders and editors, that approach feels like overkill.

There should be a more automated tool to give a list of parameters out of the box, right? That’s why the Crocoblock team has developed the Query Builder tool – a part of JetEngine – not only to automate the process but also to eliminate the need to dig into code and change it manually.

Query Builder by JetEngine

Crocoblock Query Builder

Query Builder is an extremely powerful and unique tool developed by Crocoblock for creating custom queries of any complexity, fully visually. 

While WP_Query is the backbone for fetching posts (and anything stored as a post type – blog posts, pages, custom post types, even WooCommerce products), it’s not the only query class WordPress has. There are dedicated classes for other types of data: WP_Term_Query for taxonomies, WP_User_Query for users, and WP_Comment_Query for comments. They all follow the same pattern: you pass an array of arguments, and WordPress builds the SQL for you.

Additionally, the REST API provides an external layer of access. It’s not a separate query engine, as it still relies on the same query classes under the hood; however, it delivers results in JSON for remote sites, headless setups, or front-end JavaScript applications.

This is where Query Builder comes in as a real game-changer. Instead of remembering different query classes, argument arrays, or API parameters, you have one unified visual tool. You can build complex queries for posts, terms, users, comments, or even REST output – all within the same interface, without needing to touch code. 

Simply put, Query Builder unifies the entire querying ecosystem under one roof, making it accessible to both non-developers and developers alike.

And this is how it looks:

As you can see, all existing query types are there (to activate REST API and CCT query types, enable these modules in JetEngine > JetEngine). Additionally, there are specialized types, such as Merged Query and Current Query, designed for specific use cases. There is also a query type for repeaters and even JetFormBuilder’s records. 

And, a cherry on top, there is an SQL query that allows you to query anything directly from the database using raw SQL requests (the AI helper will assist you if needed) or a visual UI. Thus, you can fetch results for even the most complex combinations of requests. Check this article for the list of use cases. 

Each query type has a list of parameters that are specific to this type, and you can adjust any of them to get what you want. Also, there is a long list of macros to refine queries even more. 

There’s a Query Preview tool to check whether your query returns anything. 

You are probably wondering now what to do with these queries after creating them, right? There are a lot of options. You can use it as a source for JetEngine’s listing template, which you can further display as a grid, slider, map, calendar, table, or even a graph. You can also use it as a source for Bricks’ query loop. Additionally, some Crocoblock plugins support query results as a source, such as JetElements, JetTabs, or JetBlog. Here, you can find more options

What Query Builder actually manipulates (under the hood)

Here is a more technical dive into what’s going on under the hood. You can simply skip it and enjoy the no-code functionality that Query Builder provides, if such details are not of interest to you. 😉

So, when you pick Posts as the query type in Query Builder, JetEngine compiles a plain WP_Query arguments array (post_type, posts_per_page, paged, orderby, meta_query, tax_query, date_query, post__in, etc.) and then runs new WP_Query( $args ) under the hood. The grid/listing UI you see is just a renderer over the resulting $query->posts. So the have_posts() / the_post() behavior you know from the Loop is a reflection of this underlying WP_Query. 

It does not alter the global/main query unless you use the special Current WP Query type. That mode hooks into the page’s already-running main query and lets you constrain things like “posts number per page” per page type, without writing pre_get_posts. 

Query Builder can also target terms (WP_Term_Query), users (WP_User_Query), comments (WP_Comment_Query), WooCommerce products (which are still posts, but of a Product CPT), CCT items, repeaters, REST API responses (fetched and mapped into items), and raw SQL via $wpdb. The UI normalizes all of these into a “query result” that the widgets can loop over. That’s why some options (e.g., pagination) are available for some types and not others. 

As a result, you have these clear advantages, not to mention the visual UI that saves you tons of time and doesn’t require any PHP coding skills:

  • Centralized and reusable configs – you save a query once and attach it to multiple widgets/pages.
  • Live preview and no typos, as you see results while building, and select most of the arguments from a list instead of typing them. 
  • Dynamic inputs. Macros (current user, current post, URL/query vars, dates, etc.) resolve at runtime, so the same saved query adapts to context.
  • Performance controls. You can cache results and hide elements when a query returns nothing, which is awkward to standardize in raw PHP snippets.

For more ideas about using Query Builder, check this article – and you will probably be surprised. 😉

FAQ

Can Query Builder fetch data beyond posts?

Yes. It supports queries for users, terms, comments, repeaters, CCT items, REST API responses, and even raw SQL queries, all managed through a unified interface.

Is Query Builder only for developers?

Not at all. Developers benefit from reusable, centralized queries, while non-coders enjoy the drag-and-drop interface with no need to edit PHP templates.

Can WP_Query handle users or taxonomies?

No. WP_Query is only for posts (including CPTs like WooCommerce products). For users, comments, or terms, WordPress provides WP_User_Query, WP_Comment_Query, and WP_Term_Query.

Summing Up

At the end of the day, WordPress gives you multiple ways to query data, but writing WP_Query arguments by hand quickly feels outdated. The free WP Query Generator was a nice helper, but JetEngine’s Query Builder takes things to a whole new level. 

It saves you from typos, endless lookups for IDs and slugs, and the pain of editing PHP files, which doesn’t even work if you use visual builders like Elementor or Bricks for creating websites.

With one tool, you can visually build queries for posts, users, terms, or even external APIs and plug them straight into your layouts. Whether you’re a developer or a site builder, it’s simply a smarter, faster way to get dynamic content on your site.

Was this article helpful?
YesNo