How to Set Individual Order for Related Items
Learn how to set the individual order for JetEngine’s related items on your WordPress website.
Before you start, check the tutorial requirements:
In this guide, we will show you how to set the individual order for JetEngine’s related items based on relations built for posts, CPTs, CCTs, users, and terms and display the changes on the front end.
Change the Order
Go to the post/user/term where the related items are set. In our case, the relation is set between the two CPTs, so we proceed to the random parent post where the related items are set.
Now, change the order by dragging the items and placing them where needed. Also, press the “Save order” button in the top right corner of the list.
Don’t forget to save the post settings as well.
Create a Query
Next, we will build a query that will help to display the related items on the front end in the changed order. The type of query should be selected according to the type of data the related data belongs to.
Depending on the type of query you want to build, the setup of the settings will vary. We will look through all the possible settings options to display the changed order of related items on the front end later.
Posts query
After setting the Name and selecting the “Posts Query” Query Type, head to the Posts Query section.
There, open the Post & Page tab and press the “Dynamic Tags” button.
Find the “Related Items” macro and click it to open its settings.
In the From relation field, pick the relation you work with, and select whether you want to display the “Parent object” or “Child object” with this query in the From object (what to show) field. For instance, we select the “Child object” option.
Also, select the needed option in the Initial Object ID From (get initial ID here). In our case, we pick the “Current Object ID” option.
Press the “Apply” button.
Return to the General tab and press the “Add new sorting parameter” button in the Order & Order By section.
Once the fields appear, select “Preserve post ID order given in the ‘Post in’ option” in the Order By field and the preferred order in the Order field. In our case, it’s set to the “From lowest to highest values (1, 2, 3; a, b, c)” option.
That’s all for the basic query customization, so whenever ready, press the “Add/Update Query” button.
Users query
To build a users query, first, give it a Name and then select the “Users Query” Query Type.
Then, head to the Include/Exclude tab and press the “Dynamic Tags” button next to the Include field.
Find and select the “Related Items” macro from the list to open its settings.
In the opened settings, select the needed relation in the From relation field, the preferred object in the From Object (what to show) field, and the required option in the Initial Object ID From (get initial ID here) field.
To save the settings, press the “Apply” button.
Next, move to the Misc tab. Here, open the Order By selector and pick the “By the included list of user IDs (requires the Include parameter)” option there.
Now, you can make the query live by pressing the “Add/Update Query” button.
Terms query
To build a terms query, complete its Name and pick the “Terms Query” Query Type.
Then, open the Include/Exclude tab in the Terms Query section.
Press the “Dynamic Tags” button next to the Include field. There, pick the “Related Items” macro to open the additional settings.
Select the relation in the From relation field, the object you want to display in the From Object (what to show) field, and the preferred option in the Initial Object ID From (get initial ID here) field (in our case, “Current Object ID”).
Once done, press the “Apply” button.
Next, return to the General tab and pick the “Match the order of the ‘Include’ param” option in the Order By selector.
That’s all for the basic settings. Now, press the “Add/Update Query” to save the result.
CCT query
To build a CCT query, complete its Name and pick the “Custom Content Type” Query Type.
Then, move to the Content Types Query section and pick the CCT you work within the From Content Type selector.
Scroll down to the Query section and press the “Add new” button.
Pick the “Item ID” Field, set the Compare operator to “In the list,” and click the “Dynamic Tags” button next to the Value field.
In the list that appeared, find and select the “Related Items” option. Then, pick the relation you work within the From Relation field, the preferred object in the From Object (what to show) field, and the needed option in the Initial Object ID From (get initial ID here) field.
Finally, press the “Apply” button to save just-set field values.
Scroll up to the Order & Order By section and push the “Add new sorting parameter” button.
Pick the “Preserve item ID order given in the query arguments” option in the Order By field, and select the desired Order. In our case, it’s set to “From lowest to highest values (1, 2, 3; a, b, c)”.
Once all the customizations are done, press the “Add/Update Query” button.
Apply Query
Now, proceed to the page where you want to use the built query. For instance, we want to query the “Tours” (child CPT) listing on the “Country” (parent CPT) Single page template (part of the JetThemeCore plugin’s functionality).
So, beforehand, we built a listing with the “Tours” source, and now we head to the “Country” Single page template built with Elementor.
There, we place a Listing Grid widget on the page template and select the built Listing in the General tab.
Then, proceed to the Custom Query tab and activate the Use Custom Query toggle. Once done, pick the built query in the Custom Query field.
Check the Result
That’s all; now, you know how to set the individual order for JetEngine’s related items on your WordPress website.