Skip Navigation

[Resuelto] Ability to create new child posts during the creation of a parent post in CRED

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

Problem:

Solution:
You can use CRED API hook cred_save_data in order to create child post and to establish relationship (connection) between your parent and child post type entry you need to add postmeta key.

When using Types posts relationships, the parent of a given type is stored in a field:

_wpcf_belongs_{parent-posttype-slug}_id

You can find proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/ability-to-create-new-child-posts-during-the-creation-of-a-parent-post-in-cred/#post-609624

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/creating-post-type-relationships/
=> https://toolset.com/documentation/user-guides/cred-api/#csd

This support ticket is created hace 6 años, 10 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 2 respuestas, tiene 2 mensajes.

Última actualización por larryB-3 hace 6 años, 9 meses.

Asistido por: Minesh.

Autor
Mensajes
#609547

Tell us what you are trying to do?
I have a parent post type called "Facility Report" that basically only has a couple of fields. I also have numerous child post types for that parent that a user could choose to create when completing a Facility Report. I'm looking to create a front-end form using CRED where a user starts a new Facility Report, completes a couple of data fields and is then presented sections on the form for each of the child post types, for example "landscaping", "gates", and "clubhouse". The user should be able to click on something, maybe a "+" and complete the couple of fields associated with that child post type as necessary. Repeating with the other children sections also. When all done, the main parent post type of Facility Report is then created and when viewed you could see the parent fields and the child post fields that were completed.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#609624

Minesh
Supporter

Idiomas: Inglés (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you can use CRED API hook cred_save_data in order to create child post.

Considering that you have created parent/child relationship using Types:
=> https://toolset.com/documentation/user-guides/creating-post-type-relationships/

Now, you can use CRED hook: cred_save_data to manipulate your data and create child post
=> https://toolset.com/documentation/user-guides/cred-api/#csd

Using above hook you can create child entry using the WordPress function - wp_insert_post:
=> https://developer.wordpress.org/reference/functions/wp_insert_post/

To establish relationship (connection) between your parent and child post type entry you need to add postmeta key. When using Types posts relationships, the parent of a given type is stored in a field:

_wpcf_belongs_{parent-posttype-slug}_id

Let’s assume that we are displaying a Car post type that has a Maker as a parent post type.
Each Car will store its Maker (parent) id in the field _wpcf_belongs_maker_id.

update_post_meta($child_post_id, '_wpcf_belongs_maker_id', $post_id);

Please check following related ticket that may help you:
=> https://toolset.com/forums/topic/automatic-post-creation-on-registration/#post-555243

#609950

Thank you.