Problem: Instead of the standard CRED select field, I would like to use a custom select field in my CRED form to choose a taxonomy term I wish to associate with this post.
Solution: Use the following template to create your select element:
<select name="category"> <option>- Select a model -</option> <wpv-loop> <option value="[wpv-taxonomy-id]">[wpv-taxonomy-title]</option> </wpv-loop> </select>
Then update your functions.php file to capture and store the selected term along with the post:
//Create a dynamic category by the CRED form. add_action('cred_save_data','func_save_cat_id_for_cred_post',10,2); function func_save_cat_id_for_cred_post($post_id,$form_data) { if ($form_data['id']==6814) { wp_set_post_terms( $post_id, $_POST['category'], 'category', false ); } }
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Function_Reference/wp_set_post_terms
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 4 replies, has 2 voices.
Last updated by PhantomPWR 6 years, 7 months ago.
Assisted by: Christian Cox.