Problem: I have 6 Forms that create custom posts. For each Form, I would like to automatically set one term in a custom taxonomy when the post is published.
Solution: Use the cred_save_data API to programmatically set a term specific to each Form for the published posts:
/* - Toolset support - for ticket #1691935 - */ // Bewerber: 13 = VR, 399 = Berater, 403 = Sportler; Inserate: 255 = VR, 584 = Berater, 586 = Sportler add_action('cred_save_data', 'ts_set_industry_term',100,2); function ts_set_industry_term($post_id, $form_data) { $forms = array( 13, 399, 403, 255, 584, 586 ); $terms = [ '13' => 'vr-mandate', '399' => 'berater-innen', '403' => 'sportler-innen', '255' => 'vr-mandate', '584' => 'berater-innen', '586' => 'sportler-innen', ]; $taxonomy = 'profil'; // -- you should not edit anything below this line if( in_array( $form_data['id'], $forms ) ) { $tag = array( $terms[$form_data['id']] ); wp_set_object_terms( $post_id, $tag, $taxonomy, true ); } };
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 5 replies, has 2 voices.
Last updated by 4 years, 5 months ago.
Assisted by: Christian Cox.