Problem: I have a Form that creates parent posts. There is a generic checkbox in the Form. If the checkbox is checked, I would like to automatically create a child post.
Solution: Use the cred_save_data API to create a post automatically, use the toolset_connect_posts API to automatically link the new child post to the new parent post, and test the checkbox by testing if the slug key exists in the $_POST superglobal.
function create_child_log_item($post_id, $form_data) { if ( isset( $_POST['auto-add-log-item'] ) ) { $log_item = array( 'post_title' => $title, 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'log-item', 'meta_input' => array( ), ); $log_item_id = wp_insert_post( $log_item , $wp_error ); if ( $form_data["id"]==283 ) { toolset_connect_posts( 'maintenance-task-log-item', $post_id, $log_item_id ); } } } add_action("cred_save_data","create_child_log_item",10,2);
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
https://developer.wordpress.org/reference/functions/wp_insert_post/
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 |
---|---|---|---|---|---|---|
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 6 réponses, has 2 voix.
Last updated by davidS-53 Il y a 5 années et 5 mois.
Assisted by: Christian Cox.