Problem: I have two post types - Hosts and Structures - in a post relationship. Each User can be the author of one Host post, and can create multiple Structure posts using Forms. When the User submits a Form to create one of these Structure posts, I would like to automatically connect it to the User's Host post.
Solution: Use the cred_save_data API to trigger custom code when the Structure post is created. Use the toolset_connect_posts API to link the two posts programmatically.
add_action('cred_save_data', 'func_connect_host_with_property',10,2); function func_connect_host_with_property($post_id, $form_data){ if ($form_data['id']==43){ $current_user_id = get_current_user_id(); $args = array( 'author' => $current_user_id, 'post_type' => 'proprietario', 'fields' => "ids"); $found_profile = get_posts($args); if(count($found_profile) > 0){ toolset_connect_posts( 'proprietario-struttura',$found_profile[0], $post_id ); } } }
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
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 5 replies, has 2 voices.
Last updated by 3 years, 11 months ago.
Assisted by: Christian Cox.