Skip Navigation

[Resolved] Auto-Assigning Category to Form

This support ticket is created 5 years, 11 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
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)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1194012

We found a code on a Toolset support ticket to link a specific category to a form. https://toolset.com/forums/topic/want-cred-form-to-post-to-default-category/

We need help troubleshooting the code since it doesn't seem to be working on our site (perhaps due to a Toolset update since the code was posted?)

Site is Localecopia.org

#1194016

Try this code instead:

add_action("cred_save_data", "ts_automatically_set_term",10,2);
function ts_automatically_set_term($post_id, $form_data)
{
// if a specific form
if ($form_data["id"]==123)
{
  $category_ids = array(456);  // replace your category ID
  wp_set_object_terms( $post_id, $category_ids, 'taxonomyslug');

}

Replace 123 with your Form ID. Replace 456 with the term ID (or a comma-separated list of term IDs). Then replace taxonomyslug with the slug of the taxonomy that contains the term(s).