Help Center

How to Use WP Query Generator to Query the Posts

How to Use WP Query Generator to Query the Posts

This tutorial describes the way of working with one of Crocoblock's development tools that helps you simplify the work of creating custom queries a bit.

Here we are going to learn about WP Query Generator options and how they work. As you can see there are 9 tabs in the WP Query Generator tool so let’s take an overview of each of them.

General Parameters

This tab generates the code for ordering posts by following criteria:

  • post type (put the specific post’s slug in this field);
  • post status (select the post’s status e.g. draft, publish, private);
  • order (the ascending or the descending order);
  • order by (the parameter for posts ordering).
general parameters

Pagination Parameters

This tab is a place where you can specify how the user will achieve the posts, how they will be separated into pages, how many posts should be skipped from being displayed. Here you can define the next information:

  • posts per page (the number of posts to show per page);
  • offset (hide the posts that already were shown);
  • paged (specify the pages where posts will be displayed);
  • page (the number of posts per static page);
  • ignore sticky posts (ignore posts stickiness while showing);
pagination parameters

Post & Page Parameters

This tab allows excluding or including some post and defining which parent pages are in list or not. Fill the next information to retrieve posts by:

  • post ID (the post’s ID);
  • post name (post’s slug);
  • post title (the title of post);
  • page ID (the page’s ID);
  • page name (the title of page);
  • page parent (ID of parent page);
  • page parent in (ID of the parent page);
  • page parent not in (ID of the parent page);
  • post in (ID of the post that is included);
  • post not in (ID of the post that is excluded);
  • post name in (a slug of the post that is included).
post and page parameters

Author Parameters

This tab allows to query the posts by authors. All you need to do is to set the author’s ID and Name in the following fields:

  • author (ID);
  • author name (use “user_its name” – NOT name).
author parameters

Category & Tag Parameters

This tab allows displaying the posts by their tags and categories. You can also exclude the posts by category ID, slug, or the specific tags:

  • category (ID);
  • category name (slug);
  • category and (ID of the category to display);
  • category in (ID of the category to display);
  • category not in (ID of the category that is excluded);
  • tag (slug);
  • tag ID (ID);
  • tag and (ID of the tag to show);
  • tag in (ID of the tag to show);
  • tag not in (ID of the tag that is excluded);
  • tag slug and (slug of tag);
  • tag slug in (slug of tag).
category and tag parameters

Tax Query Parameters

This tab generates the posts query by custom taxonomy terms. To retrieve the needed posts use the specific taxonomy terms:

  • click the Add New button to add an aditional query to apply together with the one already set.

Note, that you can add as many queries as you need and then only set the relations between them.

tax query parameters

Meta Query Parameters

This tab allows displaying posts by meta key values. This query will come in handy if you want to showcase product post types and the prices:

  • click Add New button in order to add an extra meta value field to set the query and select the relation beetwen them.
meta query parameters

Date Query Parameters

This tab allows creating a query for displaying posts that are published before or after the set date:

  • click the Add New button and you get advanced settings (e.g. Year, Month, Week, etc.);
  • you can add as many additional query as you wish and than apply the needed relation between them in the Relation dropdown.
date query parameters

Misc Parameters

This tab has five extended settings where you can:

  • set password in the Has password field;
  • if you decided to set the password for pulling out the post, type it in the Post password field;
  • show only the posts that have the comments and define the excerpt for comments to display;
  • you can also define if the posts will be displayed only for the users that have access to them in the User permission field;
  • besides, you can define the post mime types for posts query.
misc parameters

After you have specified all features for posts query you will get the json code which you need to copy in the Generated Query section.

generated query section

Proceed to Posts widget’s settings, open the Content > General directory, enable the Use Custom Query option and paste the code in the empty field.

custom query settings in posts widget

In case you are using Smart Posts List, navigate to the Content > Query & Controls, turn on the Use Custom Query option and put the code in the empty field.

custom query settings in smart posts list widget

Was this article helpful?
YesNo

Need help?

Ask Facebook community

Get answers from 22K Crocoblock Community experts from all over the world.

Start a live chat

Ask question to support agent and share its details via chat messages.