Skip Navigation

[Resolved] CRED create new child post with parent set automatically.

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

Problem:
how to create new child post with CRED and set parent automatically
Solution:
You should try to use CRED generic hidden field to set parent.

For example:

[cred_generic_field field='_wpcf_belongs_home_id' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/cred-create-new-child-post-with-parent-set-automatically/#post-895116

Relevant Documentation:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

This support ticket is created 6 years, 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#894660

Hi

I have a child with some post types, one of which is a parent of the other. I'll use the example of house and rooms.

So a house is the parent of multiple rooms.
On the page of "House 1" the rooms are listed. The page also pulls in an "Add new room" CRED form.
The user can fill in the form and add a new room.

How do I automatically set the parent of the the newly added room equal to the house page that the user is on.

I can see how to add a drop down so the user can select the house, but I don't want them to have a choice. They're on a house page and any room they add should automatically be a child of that house.

Thanks for your help

#894664

I've found a way to do it:

	<div style="display:none">
		[cred_field field='_wpcf_belongs_home_id' value='[wpv-post-id]' select_text='' class='form-control' output='bootstrap']
	</div>

Is that recommended or is there a better way to achieve this?
Thanks

#895116

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - if you just do not want to display the parent field - you should try to use following code:

[cred_generic_field field='_wpcf_belongs_home_id' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

More info:
=> https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

#896509

Thanks Minesh that's a better solution.

Note that you've got an extra ' in there.
"default":"[wpv-post-id']"
should be
"default":"[wpv-post-id]"

#896532

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you - I've corrected the typo 🙂