Back to Tips & Tricks

JetFormBuilder Connect Relation Items Not Working: Parent-Child Fix

BoostMyCroco TeamPublished on
Parent node linked to several child nodes, illustrating a JetFormBuilder form connecting child posts through a relation

When JetFormBuilder's Connect Relation Items action is not working, the cause is usually one of three things. The form sends the wrong ID as the Parent Item ID, the Child Item ID is not the post the form just created, or the actions run in the wrong order. To fix it, run Insert/Update Post first. Then add Connect Relation Items after it with inserted-post-id as the Child Item ID, and take the Parent Item ID from a field that really holds a parent post ID.

If the link saves but the parent's Listing Grid shows every child post, jump to the Listing Grid section. The examples use parent CPT Properties, child CPT Inspections and a One to Many relation. They use the current JetFormBuilder and JetEngine Relations UI, not the legacy JetEngine > Forms builder.

How a one-to-many relation decides which side is the parent

Every JetEngine relation has a parent object and a child object. For "one property has many inspections", set it up like this:

  • Parent object: Properties.
  • Child object: Inspections.
  • Relation type: One to Many.

Open the relation in JetEngine > Relations and check the direction before you build any form. If it was registered the other way round, you have to swap every ID below.

  • Parent Item ID: the ID of a Properties post.
  • Child Item ID: the ID of an Inspections post. In a create-and-connect form, that is the post the form just inserted.

For the field that picks the parent, use a Select or Radio field. Both let the user choose one option, which fits One to Many. A Checkbox field allows several options and matches Many to Many.

Before you start:

  • JetEngine and JetFormBuilder must both be active.
  • The relation must already exist.
  • Field names must be unique within a form. Use only lowercase Latin letters, with - or _ between words and no spaces (for example parent_property).

If your relation links users rather than posts, see linking users to a CPT on the front end.

Form 1: create the parent post

A new property has no inspections yet, so this form does not touch the relation. The link is made later, from the child side.

  1. Go to JetFormBuilder > Add New.
  2. Add a Text field named property_title, plus any other fields you need.
  3. In Post Submit Actions, add Insert/Update Post. Set Post Type to Properties and Post Status to Published.
  4. In the Fields Map, map property_title to Post Title.

No Connect Relation Items action is needed here.

Form 2: add a child post and connect it in the same submit

  1. Go to JetFormBuilder > Add New and add a Text field named inspection_title.
  2. Add the field that carries the parent ID and name it parent_property. Its type depends on where the form sits (see the next section).
  3. In Post Submit Actions, add Insert/Update Post. Set Post Type to Inspections and Post Status to Published.
  4. In its Fields Map, map inspection_title to Post Title. Leave parent_property on "Select post property", because the parent ID is not a property of the new post.
  5. Click + New Action and add Connect Relation Items below the Insert/Update Post action. Set:
    • Relation: your Properties to Inspections relation.
    • Parent Item ID: the parent_property field.
    • Child Item ID: inserted-post-id, the ID of the post the previous action created.
    • Update Context: leave it empty.
    • How to Store the New Item: choose the option that fits your setup. The official guide linked below describes the options.
  6. Save the form and submit a test entry.

The order matters. Connect Relation Items needs the inserted post ID, and that ID exists only after Insert/Update Post has run. For every setting, see the official JetFormBuilder guide to connecting related items.

Where does the parent ID come from? Three setups

(a) Form on the Properties single template: Hidden Field with Current Post ID

Add a Hidden Field named parent_property and keep its default value, Current Post ID. It returns the ID of the post where the form is placed. On the Properties single template, that is the property being viewed, so it is the correct Parent Item ID.

(b) Form on a separate page: Select or Radio filled from Properties

Add a Select or Radio field named parent_property. Set Fill Options From to Posts and Post Type to Properties. The user picks the property. The selected value is the property's post ID, which you map as the Parent Item ID.

(c) Link from the property to a form page: Hidden Field with URL Query Variable

Use this when the property's page sends visitors to a separate form page.

  1. On the Properties single template, add a button that links to your form page with the property's ID in the URL, for example a link ending in ?property_id=123. Build the link with a JetEngine Dynamic Link or a dynamic tag that outputs the current post ID. The exact option differs between setups, so confirm it in your JetEngine version.
  2. On the form page, add a Hidden Field named parent_property and choose URL Query Variable.
  3. In the variable name setting your version shows, enter the same parameter name as the link (property_id here). If you don't see that setting in the field, check the Hidden Field's Dynamic Tag "Edit Preset" pop-up, which also lists URL Query Variable as a SOURCE.

To confirm it works, open a property, click the button and check that the form page URL contains the property's ID. Then submit a test inspection and check that it appears on that property.

Why setup (a) breaks on a normal page

Current Post ID always means "the post that holds this form". On a regular page it returns that page's ID, not a property's. The inspection gets created but is linked to nothing or to the wrong object. If the form has to live outside the property's single template, use setup (b) or (c).

Show only this parent's children in a Listing Grid

A Listing Grid that only has Inspections as its post type shows every inspection on the site. To limit it to the current property's inspections, filter the query with the Related Items macro.

  1. Go to JetEngine > Query Builder > Add New. Choose the Posts Query type and set Post Type to Inspections.
  2. In the Post & Page section, click the macros icon next to Post In and choose Related Items.
  3. Set From Relation to your relation, From Object to Child Object, and Initial Object ID From to Current Object ID.
  4. Open the macro's Advanced settings and set Fallback to a non-existent ID such as 0. Save the query.
  5. Open the Properties single template and add a Listing Grid that uses your Inspections listing item.
  6. In the Listing Grid's Custom Query section, enable Use Custom Query and select the query.

Open two properties on the front end. Each should list only its own inspections. With the fallback set, a property with no inspections shows none. Without the fallback, the macro finds nothing and the query usually returns every inspection, which looks exactly like an unfiltered grid.

The current relation macros work with relations created after the JetEngine 2.11.0 update. Legacy relation macros work only with legacy relations, so a macro copied from an old tutorial will not filter a newer relation. The JetEngine relations macros page covers both. For other query pitfalls, see our JetEngine Query Builder mistakes and fixes.

Children inside tabs or inside a parent listing

The Initial Object ID From setting decides which object the macro starts from:

OptionWhich object it usesUse it when
Current Object IDThe current post on a single page, or the current item when the grid sits inside another listingThe grid is placed directly on the property's single template, or nested inside a Properties listing so each item shows its own inspections
Default WordPress Object (for current page)Always the page's global object, even inside a listing added to that pageThe grid sits inside a listing item of another post type on the property's page and must always follow the page's own property

If the grid sits inside tabs, test which option returns the right property in your setup. The docs only describe the difference for listings.

If you need the macro as text, for an SQL query for example, generate it in WordPress Dashboard > JetEngine > JetEngine > Macros Generator by choosing Related Items. The output looks like %rel_get_items|23|child_object|current_object|%. Crocoblock's SQL example adds a fallback: %rel_get_items|23|child_object|current_object|%{"fallback":"0"}. The 23 belongs to the example relation, so generate your own macro instead of editing the number. To combine children from two relations in one grid, follow Crocoblock's several-relations guide.

Troubleshooting checklist

SymptomCauseFix
Child post is created but linked to nothing or to the wrong parentA Hidden Field with Current Post ID on a normal page returns the page IDMove the form to the Properties single template, switch to a Select/Radio filled from Properties, or pass the ID in the URL and read it with URL Query Variable
Relation is not saved on a create-and-connect formWrong Child Item ID, Update Context filled in, or actions in the wrong orderSet Child Item ID to inserted-post-id, leave Update Context empty, and place Insert/Update Post above Connect Relation Items
Parent and child are swappedThe Parent Item ID field holds an Inspections ID, or the relation was registered the other way roundSwap the two fields in the action, or fix the relation's parent and child objects
Existing links disappear after an edit formA filled Fields Map in Insert/Update Post makes new related items replace the old ones. Unticking a pre-ticked child also disconnects it.In relation-update forms, leave the Fields Map empty. Unticking removes the link by design.
Listing shows every child postOne of three causes: the Listing Grid is not using the Related Items query; the macro has no fallback, so a parent with no children returns all posts; or a legacy macro is used on a current relationEnable Use Custom Query and pick the query. Set the macro fallback to a non-existent ID such as 0. Use the current Related Items macro.
A grid inside a listing item of another post type on the property page shows the wrong parent's childrenCurrent Object ID takes the current listing item, not the page's propertyUse Default WordPress Object (for current page). Keep Current Object ID for grids nested in a Properties listing.
Listing shows nothingThe same query is set as the listing template's source and again in the Listing Grid's Custom Query tabKeep it in one place only

Find the symptom you see in the table. Then test with one property that has inspections and one that has none. If you would rather have this flow built for you, post a request on BoostMyCroco.

Frequently Asked Questions

Can I link one child post to several parents with JetFormBuilder checkboxes?
Not in a One to Many relation. There each child belongs to one parent, so a Select or Radio field is the right choice. A Checkbox field allows several options and matches a Many to Many relation, so if inspections really need several properties, change the relation type first.
Does the old JetEngine > Forms relation setup still work?
Building relation forms under JetEngine > Forms is documented as legacy. Current setups use JetFormBuilder > Add New with the Connect Relation Items post submit action. New projects should use JetFormBuilder.
Why does my related posts listing work on one site but not another?
Check when the relation was created. The current relation macros work with relations created after the JetEngine 2.11.0 update, while legacy macros work only with legacy relations. Mixing them leaves the Listing Grid unfiltered.
Why does a parent with no children show every child post?
When the Related Items macro finds nothing and has no fallback, the query usually ignores the filter and returns all items. Open the macro's Advanced settings and set Fallback to an ID that does not exist, such as 0. The empty parent then shows no results.
How do I check that the relation was saved after submitting the form?
Open the parent's single page with a Listing Grid filtered by the Related Items query, with a fallback set, and look for the new child. If the child post exists but does not appear there, check the Child Item ID, the action order and the Parent Item ID field in the form.

This guide answers a question from our community: Is someone able to help me tweak my forms connection to listings?

Sources

  1. JetFormBuilder: Connecting WordPress Related Items with Post Submit Actions (jetformbuilder.com)
  2. Macros for WordPress Relations — JetEngine (crocoblock.com)
  3. Displaying Related Items From Several Relations in One Listing — JetEngine (crocoblock.com)
  4. How to Connect Relation Items Using Forms (crocoblock.com)
  5. Hidden Field Overview ㅡ JetFormBuilder (jetformbuilder.com)

Related tips