Problem: I have a CRED form that allows Users to create child posts using CRED. They can select a parent post in the CRED form. I would like to use the parent post title as the child post title.
Solution:
Automate this with PHP using the cred_save_data hook:
add_action('cred_save_data', 'copy_parent_title_to_child',10,2); function copy_parent_title_to_child($post_id, $form_data) { // if a specific form if ($form_data['id']=='12345') { if (isset($_POST['_wpcf_belongs_parentslug_id'])) { $my_post = array( 'ID' => $post_id, 'post_title' => get_the_title($_POST['_wpcf_belongs_parentslug_id']) ); wp_update_post( $my_post ); } } }
Replace the form ID and custom post type slug, and remove the post title field from the child post CRED form.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 11 months ago.
Assisted by: Christian Cox.