Back to Tips & Tricks

JetEngine: Show Related Users on a Single Post With a Relation

BoostMyCroco TeamPublished on
Illustration of one central post node linked to several user figures, representing JetEngine related users on a single post

To show related users on a single post in JetEngine, create a relation with your post type as the Parent object, Users as the Child object and the Relation type set to One to many. Next, build a Users Query in the Query Builder. Put the Related Items macro in its Include field, set it to Child Object and Current Object ID, and select that query under Custom Query in the Listing Grid on your single post template. If the grid shows every user, the custom query is usually missing, points at the wrong object, or has no fallback for posts without linked users.

This guide follows one example from start to finish. An Agencies custom post type is the parent, and WordPress users in an Agent role are the children. Each agency page lists its own agents, and each agent belongs to one agency. The role only keeps things organized. The relation links users whatever their role is.

What you are building

A JetEngine relation always has two sides: a parent object and a child object. Each side can be a post type, a taxonomy, a Custom Content Type or Users. In a One to many relation, one parent can have many children, and each child is meant to have only one parent. JetEngine's own example is an author with many books, where each book has a single author.

You want one agency with many agents, where each agent belongs to one agency. That means:

  • Parent object: the Agencies post type
  • Child object: Users
  • Relation type: One to many

Direction matters. If you make Users the parent and Agencies the child, One to many means one user can have many agencies. That is the opposite of what you want.

Create the relation in JetEngine > Relations

  1. Go to WordPress Dashboard > JetEngine > Relations > Add New.
  2. In Name, enter something clear such as Agency Agents. This name appears later in the macro and dynamic tag settings, so make it easy to recognize.
  3. Set Parent object to your Agencies post type.
  4. Set Child object to Users.
  5. Set Relation type to One to many.
  6. Set the control toggles as shown in the table below, then save the relation.
SettingValueWhy
Register controls for parent objectOnAdds the box for connecting agents to the agency's edit screen.
Register controls for child objectOn (optional)Adds the same kind of box to the user edit screen, so you can pick the agency from the agent's profile.
Allow to create new parents from childrenOn if you link from the profileThe settings describe it as creating new parent items from the child's screen. Crocoblock's documentation on editing related items lists it, together with Register controls for child object, for working with parents from the child side.
Require at least one parentYour choiceWhen on, publishing a child that has no related parent is stopped and the message Should have at least one related parent. appears. You can change that text in the Labels tab under Child Object: no parents error. Users have no publish step, so test what happens on the user edit screen in your version before you rely on it.
Register separate DB tableOptionalWithout it, related items are stored in JetEngine's shared relations table.

Leave Allow to create new children from parent and Allow to delete children from parent off unless you need them. Here you only connect existing users to existing agencies.

Why not Many to many? Many to many is meant for linking one user to any number of agencies. If a user must belong to only one agency, it is the wrong choice. One to many is the type meant for one parent per child, so it matches the rule you want. Still, check your connections from the user side after linking, as described below.

From the agency's edit screen

  1. Open an agency in the WordPress admin.
  2. Find the Children section for your relation.
  3. Click the Connect User button. A pop-up opens with a Select field.
  4. Choose the user and confirm.
  5. Update the post to save the changes.

In this table, users are listed by their login and email, not their display name. Keep that in mind when you search for an agent. Crocoblock has a separate tip on showing the user display name in the relations list if you need it.

From the user's profile

With Register controls for child object turned on, the same related-items table appears on the user edit screen. There you connect the agent's parent agency instead. Crocoblock's documentation says editing from the child side is available when both Register controls for child object and Allow to create new parents from children are on, so turn on both if you want to manage links from the profile. The person editing also needs the right user permissions for that user.

Before you build the listing, open two or three agents and confirm that each one is connected to exactly one agency. That makes the front-end test meaningful.

Build the Users Query in the Query Builder

The Listing Grid needs a query that returns only the users connected to the agency being viewed. The Related Items macro supplies those user IDs.

  1. Go to JetEngine > Query Builder > Add New and give the query a name, such as Agents of current agency.
  2. Set the query type to Users Query.
  3. Open the Include/Exclude section.
  4. Click the macros icon next to the Include field and select Related Items.
  5. Set From Relation to Agency Agents.
  6. Set From Object to Child Object. You want the children (users) of the current agency.
  7. Set Initial Object ID From to Current Object ID. On a single agency page, this is the agency being viewed.
  8. Open the macro's Advanced settings and enter a Fallback value, such as 0 or a user ID that does not exist. This covers agencies with no agents connected yet (see the troubleshooting section below).
  9. Click Apply, then Add Query to save.

This macro works only with the relations available since JetEngine 2.11.0. Legacy relations need the legacy macros, but that does not affect this setup: legacy relations could only link one post type to another, so a post-to-user relation is always a current one. For the other Users Query settings, including the macro Fallback option, see Crocoblock's Users Query type overview. If you are new to the Query Builder, our list of common JetEngine Query Builder mistakes is worth a quick read.

Make a users listing item and add the Listing Grid

The users listing item

Create a new listing item with Users as its source and design one agent card. For example, add Dynamic Field widgets for the name and email. Crocoblock's guide on creating a listing template for users covers the source settings.

The Listing Grid on the single agency template

  1. Open the Elementor single template that displays your Agencies posts.
  2. Add a Listing Grid widget and select your users listing item.
  3. Open the Custom Query section.
  4. Turn on Use Custom Query and select Agents of current agency.
  5. Save the template.

How to check it works: on the front end, open two agencies that have different agents. Each page should list only its own agents. Then open an agency with no agents connected. The grid should be empty. If it lists users, check the Fallback value from the Query Builder step.

Why every user shows up, and other fixes

Every user appears on every agency

This makes it look as if each user is linked to every post, but the links are usually fine. A users Listing Grid shows all users unless a query limits them. Its built-in Users Query section only has general filters such as Role, Exclude roles, Include users by ID and Meta Query. It knows nothing about your relation. Fix: turn on Use Custom Query in the Listing Grid and select the query that has the Related Items macro in Include. Crocoblock explains the built-in options on its Listing Grid Users Query page.

An agency with no agents shows every user

When an agency has no connected users, the Related Items macro has no IDs to return, so the Include field can end up empty. An empty Include may not limit the query at all, which brings back the same symptom: every user in the grid. Fix: in the Query Builder, open the Related Items macro, go to its Advanced settings and set a Fallback value such as 0 or a user ID that does not exist. Then reload an agency with no agents and confirm in your JetEngine version that the grid is empty.

The wrong users appear, or none at all

  • Wrong From Object. On an agency page, From Object must be Child Object. Parent Object looks for the agency's parents, and an agency has none in this relation.
  • Nested grid. If the users grid sits inside another listing, Current Object ID follows the current listing item, not the page. Switch Initial Object ID From to Default WordPress Object (for current page) so it always uses the single agency.

A user is connected to more than one agency

One to many with Agencies as the Parent object and Users as the Child object is the relation type meant for one parent per child. If a user shows more than one agency, first check the relation type and direction in JetEngine > Relations. Then remove the extra link from the user's profile or from the agency's edit screen, and update to save.

Links seem to disappear

After connecting users with the Connect User button on the agency's edit screen, update the post. The changes are saved only then.

No relation box on the user profile

The box on the user edit screen is added by Register controls for child object, so turn that toggle on in the relation settings. Crocoblock's documentation on editing related items also lists Allow to create new parents from children for working with parents from the child side, so turn it on too if you want to manage links from the profile. Also check that the account you are using has permission to edit that user.

Going further

Show an agent's agency on their profile

Reverse the logic with a posts query:

  1. Go to JetEngine > Query Builder > Add New, choose Posts Query and set the post type to Agencies.
  2. Click the macros icon next to the Post In field and select Related Items.
  3. Set From Relation to Agency Agents and From Object to Parent Object.
  4. Set Initial Object ID From to Queried User ID on a Profile Builder user page, or to Current User ID to show the logged-in user's own agency. Add a Fallback here too, as above.
  5. Create a listing item for Agencies, place a Listing Grid on the user page template, turn on Use Custom Query and select this query.

Filter the agent list

Once the related users show up correctly, you can add filters on top of the grid. Our guide to filtering users by a related CCT field with JetSmartFilters shows a similar users-plus-relation setup.

Limit who sees the section

You can hide the agents grid from visitors with a visibility condition on the widget or section. Choose the tool that fits your stack, and test it while logged out.

That is the whole setup: a One to many relation with the post type as parent, users connected from either side, and a Users Query with the Related Items macro and a Fallback, selected under Custom Query. If you would rather have this built for you, post a request on BoostMyCroco.

Frequently Asked Questions

Can a WordPress user belong to more than one post with a JetEngine relation?
Many to many is the relation type meant for linking one user to several posts. If each user should belong to only one post, make the post type the Parent object and Users the Child object, and use One to many, the type meant for one parent per child. After linking, check the user's profile and remove any extra link you find.
Why does my JetEngine users Listing Grid show all users?
A users Listing Grid lists every user unless a query limits them, and its built-in settings do not use your relation. Create a Users Query with the Related Items macro in the Include field, then turn on Use Custom Query in the Listing Grid and select that query.
Why does a post with no linked users still list every user?
With no related users, the Related Items macro has no IDs to put in the Include field, and an empty Include may not filter anything. Open the macro's Advanced settings in the Query Builder and set a Fallback value such as 0 or a non-existent user ID. Then test a post with no linked users to confirm the grid is empty in your JetEngine version.
Why does the relation box show user logins instead of names?
By default, JetEngine lists users in the related items table by their login and email, while posts and terms are shown by title. Crocoblock publishes a separate tip called Showing User Display Name in the Relations List if you want names there instead.
Does the Related Items macro work with legacy JetEngine relations?
No. The Related Items macro works only with relations created since JetEngine 2.11.0, and legacy macros work only with legacy relations. A post-to-user link is always a current relation, because legacy relations could only link post types to each other.

This guide answers a question from our community: Connect a User to a CPT. And show only users connect to the specifc post of this CPT on a Listing on the Single Post page of this Post.

Sources

  1. Showing User Display Name in the Relations List — JetEngine (crocoblock.com)
  2. Macros for WordPress Relations — JetEngine (crocoblock.com)
  3. Query Builder Users Query Type — JetEngine (crocoblock.com)
  4. How to Create a Listing Template for Users — JetEngine (crocoblock.com)
  5. How to Use Users Query Settings in Listing Grid — JetEngine (crocoblock.com)
  6. Jet Engine: Add user Relation · Issue #2131 · Crocoblock/suggestions · GitHub (github.com)
  7. JetEngine Relation with users - Admin Columns (admincolumns.com)
  8. WordPress Relations Feature Settings Overview — JetEngine | Crocoblock (crocoblock.com)
  9. How to Set Posts Relations (Legacy) | Crocoblock (crocoblock.com)
  10. Related Items Editing Overview — JetEngine | Crocoblock (crocoblock.com)

Related tips