Skip Navigation

[Resolved] CRED: Add Child Content and Update Parent Attribute

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

Problem:
In a Parent/Child Post relationship, is it possible to update an attribute (or more) on the parent post when submitting new content for the child post via a CRED form?

Solution:
Please modify and add following code in your theme’s or child theme’s functions.php file:

/* Update Parent Field on Child Post creation */
add_action('cred_save_data', 'update_parent_field_on_child_creation',10,2);
function update_parent_field_on_child_creation($post_id, $form_data)
{
    // if a specific form
    if ( $form_data['id'] == 2448 ) {
         
        $parent_id = get_post_meta($post_id, '_wpcf_belongs_property_id', true); // property = your parent post type name
        update_post_meta($parent_id, 'wpcf-status', 'closed'); // wpcf-status = your field name
        // closed = your field new value  
     
    }
}
This support ticket is created 7 years, 4 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#544558

In a Parent/Child Post relationship, is it possible to update an attribute (or more) on the parent post when submitting new content for the child post via a CRED form?

In other words, say I have a parent post with attribute "status=open". Then I have a CRED add child post. I would like that when I submit the new child content, the attribute "status" on the parent post gets updated to "closed".

#544625

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Noriko,

Thank you for contacting Toolset support.

Please modify and add following code in your theme’s or child theme’s functions.php file:

/* Update Parent Field on Child Post creation */
add_action('cred_save_data', 'update_parent_field_on_child_creation',10,2);
function update_parent_field_on_child_creation($post_id, $form_data)
{
    // if a specific form
    if ( $form_data['id'] == 2448 ) {
		
		$parent_id = get_post_meta($post_id, '_wpcf_belongs_property_id', true); // property = your parent post type name
		update_post_meta($parent_id, 'wpcf-status', 'closed'); // wpcf-status = your field name
		// closed = your field new value  
	
    }
}

Thank you

#544864

Thank you so much, Noman. It works like a charm.