Skip Navigation

[Resolved] Select parent field using generic form generic select and connect parent

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

Problem:
How to assign parent post while creating child post using CRED generic field.

Solution:
Using CRED hook: cred_save_data you can save the generic field "_wpcf_belongs_schools_id" value.

You can find the proposed solution with the following URL:
=> https://toolset.com/forums/topic/select-parent-field-using-generic-form-select/#post-526080

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#csd

This support ticket is created 6 years, 11 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
- 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 2 replies, has 2 voices.

Last updated by Greig Neilson 6 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#526063

I have a CRED form that I'm using to create a post and in doing select a parent. The child post is an Application and the parent post is a School.

The form field relies on a view which selects the post_id and the school name from another CPT. I know these are working because I can display them on the form the post id and name are correct.

Here's my code to select the parent:

[cred_generic_field field="_wpcf_belongs_schools_id" type="select" class="" urlparam="" value=""]
{
"required":1,
"validate_format":0,
"persist":1,
"default":"",
"options":[[wpv-view name="select-enrolment-schools"]]
}
[/cred_generic_field]

The post saves correctly but fails to establish a relationship to the parent.

Thanks in advance for your help 🙂

#526080

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you need to use CRED hook: cred_save_data to save the generic field "_wpcf_belongs_schools_id" value.

You need to use WP standard function update_post_meta. For example:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==9999)
    {
        if (isset($_POST['my_custom_field']))
        {

           $school_id = $_POST['_wpcf_belongs_schools_id'];
            // add it to saved post meta
            update_post_meta($post_id, '_wpcf_belongs_schools_id',$school_id);
        }
    }
}

Where:
- Replace 9999 with your original CRED form ID.

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#csd

#526387

Worked perfectly, thanks Minesh 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.