Back to contents

JetElements Posts widget: how to use custom query to display certain posts

Continue reading this tutorial in order to learn how to create a custom query and add it in JetElements Posts widget for arranging the posts in a certain order.

We are presenting how to work with WP Query Generator generating arguments for WP_Query class to present the posts according to the set query parameters using the Posts widget from JetElements.

Creating a custom query in WP Query Generator

Step 1 – First of all, we should open the WP Query Generator tool and start setting the needed parameters for creating a custom query.

WP Query Generator

Step 2 – We need to specify the post type slug, which is Post in our case.

Step 3 – In Post status field we can select what posts to display (such as publish, pending, draft, etc.). We want to show published posts, so we have chosen the Publish option.

Step 4 – Then we designate the ASC order parameter the queried posts will be showcased in the ascending order.

Step 5 – Last but not least, we specify the Order by parameter, such as Name to order the posts by their names.

Step 6 – When all parameters are set, we can see the generated query below. It can be copied in JSON or PHP format. We click Copy to Clipboard button and proceed with customizing the Posts widget in Elementor.

WP Query Generator generated query

There are a lot of varied parameters, which can be set according to your needs and purposes. You can learn more about the provided parameters here.

Adding a custom query to the Posts widget

Step 1 – In Elementor editor we open the page, where we use the Posts widget and click Edit Posts button.

Posts widget for Elementor

Step 2 – On the left, we see the panel with various settings for the widget. In the Content tab, we find the Custom Query subsection and enable Use Custom Query option moving the toggle.

Posts widget

Step 3 – After that, we input the generated query in the field below.

Posts widget custom query

Step 4 – Everything is done. Now the posts are displayed in the adjusted order using custom query method.

Posts widget layout
Try to use a custom query in the JetElements Posts widget and you will be impressed by how useful and easy it is.