Skip Navigation

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por Minesh hace 6 años, 6 meses.

Asistido por: Minesh.

Autor
Mensajes
#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

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Thank you - I've corrected the typo 🙂