Skip Navigation

[Resolved] Connect child post to parent in a form

This thread is resolved. Here is a description of the problem and solution.

Problem:
A form to publish child posts is included directly in the template for the parent posts (not linked to separately). How to automatically set the parent in the relationship field?

Solution:
You can provide a default value when inserting/editing the relationship field, and use the shortcode wpv-post-id for the value, which will insert the id of the post where the form is shown (i.e. the parent post).

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 12 replies, has 2 voices.

Last updated by MarcelS443 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1204092

Hey Guys,

Ok so to start off with, I did check the doc's first, and amonth others found this link https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/ which explains how to bind a child post to a parent post when submitting the form...

But with the latest update, I no longer see the fields in the insert options to do this?
I've created a form, and added it to my parent post type page, so that they can submit a booking on the page, but when I try and link the two, I do not find any trace of a link to be created, no parent post ID to insert, no relationship value to link to nothing...

After the last updates, how can I go about doing this now?

#1204243

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

image1550816951917.png

Hi Marcel

In the new Form builder the field to select the parent post is no longer included by default, you have to drag it in an add it where you want.

Please see this screenshot.

(I've passed a note to the documentation team to update the link you shared.)

#1204553

OK but now the question becomes... How can I have it always linked to the current open parent item?
And then hide it?

I assume CSS to hide it, which is fine. BUt how can I directly link it to the current open form?

#1204564

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

#1204982

The guide does not show how to set the default though?
Would you be able to advise how to do that part?

The page is a themer page from BB that I am building the layout with...

#1205420

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-02-25 at 09.49.56.png

If it is not clear from that link, the parent can be preselected when you link to the child post form from the template to display parent posts.

In the example in the documentation, venue is a parent post type, event is a child post type.

The form to publish child events includes the parent selector field and is inserted on some page.

The template to display venues includes a button to add an event (publish a child post), which is a link to the page where the child post form is shown.

You insert that link using the Toolset Forms button (screenshot), and the link that is generated will add a URL parameter that specifies the parent post that is passed to the page with the child form which the child form uses to pre-select the parent.

#1205438

The link option will not work though, We have a custom post type page, which is built in beaver themer, in that page, there is 2 related forms, the booking and reviews, both needs to be submitted without browsing to a sepeate page, so the link option does not work...

How can I set the values for those two when the page which is open? So in other words, the page they're on, is the parent post...

#1205533

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-02-25 at 11.52.20.png

In that case if you want to include the form to publish a child post directly on the parent post then when inserting the parent selector field in the form you can provide the default value with the wpv-post-id shortcode (which will output the post id of the post where the form is displayed, i.e. the parent post in this case).

#1205589

Awesome exactly what I wanted to know...
I do see however, on a relational field I cannot add a css class?

How am I to hide the field without going into the advanced mode?

#1205636

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

With the new editor if you want to make any kind of customisation—including modifying classes that are added to the wrapper div around a field and its label—then you need to switch mode, to the "expert" mode.

It is called expert mode, but is the same editor that existing in previous versions of Forms.

#1205704

I get that. But I love the editor (simple mode if you will), Adding something simple like a class option to all elements is a must I think 😉

Sometimes it's just better to keep things simple. We deal with enough code already 😉

#1206032

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Understood.

I suggest you file a feature request to add custom CSS classes (and IDs, while you're at it) to the fields when inserted with the drag and drop editor at https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

Those submissions go straight to the product manager who prioritises development work.

#1206187

My issue is resolved now. Thank you!