Skip Navigation

[Resolved] I need prepopulate a taxonomy term with Toolset Form when save the form automatically

This thread is resolved. Here is a description of the problem and solution.

Problem:
I need prepopulate a taxonomy term with Toolset Form when save the form automatically

Solution:
You can use Toolset Forms hook cred_save_data to attach taxonomy term on submit of form.

You can find the proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/i-need-prepopulate-a-field/#post-1101620

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by faustoT 6 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1101536

Hi, i want add "edizione" taxonomy with value "2019" to all post generated by a form

It's possibile to add a hidden field or something like this?
Thank you

#1101620

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - do you mean that you want to attach a specific taxonomy term to all the post created using your post form?

If yes, you can use the Toolset Forms hook cred_save_data .

For example - Please try to add following code to your current theme's functions.php file:

add_action('cred_save_data','func_set_term_dynamically',10,2);
function func_set_term_dynamically($post_id,$form_data) {

    if ($form_data['id']==99999) {

        // replace your term ID for term 2019
        $term_id = array(777);   

        // Replace here your original taxonomy slug      
        $taxonomy = 'taxonomy-slug';   

        wp_set_object_terms( $post_id, $term_id ,$taxonomy);
	
    }
}

Where:
- Replace 99999 with your original Form ID

#1101627

Thank you it works perfectly