Help Center

Showing Only Posts with Related Items

Learn how to display the posts with related items only using the JetEngine WordPress plugin.

Before you start, check the tutorial requirements:

  • Elementor (Free version), Block editor (Gutenberg), or Bricks

  • JetEngine plugin installed and activated, with a Relation set up

This guide explains how to display a list of the posts that only have the related items. You will learn how to set up a new macro to retrieve items with related items using the JetEngine WordPress plugin.

Add the Code

First, add the following code to the functions.php file of the child theme, or into the Code Snippets plugin, or any other plugin for code snippets. 

code added to the site

In this case, we use the Code Snippets plugin. Click the “Save and Activate” button. 

Adjust a Query

Proceed to WordPress Dashboard > JetEngine > Query Builder and click the “Add New” button.

Enter the Name for a query and select the “Posts QueryQuery Type. In the General tab, select the required Post Type

posts query created

Proceed to the Post & Page tab, and select the “Items with Relation” option for the Post In field. In the newly opened pop-up, select the required relation in the From Relation dropdown, and whether you need to display parents or children items from the relation in the From Object (what to show) field. Click the “Apply” button. 

items with relations macro selected

Click the “Add / Update Query” button to save the query.

Set Up a Listing Template

Following the How to Create a Listing Template for Post Types in Elementor guide, set up the Listing Template for the Custom Post Type you want to show posts from.

listing template created

Click the “Publish” button once you are ready. 

Add the Listing to the Page

Go to the page where you need to display posts with related items. Add the Listing Grid widget and select the listing template you created. In the Custom Query tab, enable the Use Custom Query toggle and select the query created earlier. 

query applied to the listing grid

Click the “Publish” button.

Check the Result

In this case, we have three posts with the connected relations.

posts with relation

On the front end, we only get these posts with the related items. 

posts with related items

That’s it. Now you know how to display the posts with related items only using the JetEngine WordPress plugin. 

Was this article helpful?
YesNo

Need help?

Ask Facebook community

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

Start a live chat

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