PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Custom Taxonomies

  1. Lee Hord
    Member

    Is there a way to accomplish this for multiple forms?

    add_filter("gform_post_data", "empty_tags", 10, 2);
    function empty_tags($post_data, $form){
        //replace 4 with your actual form id
        if($form["id"] !=4)
            return;
    
        $post_data["tags_input"] = null;
        return $post_data;
    }
    
    add_filter("gform_post_submission", "insert_custom_taxonomies", 10, 2);
    function insert_custom_taxonomies($entry, $form){
    
        //REPLACE 4 with your actual form id
        if($form["id"] !=4)
            return;
    
        //getting post
        $post_id = $entry["post_id"];
    
        //REPLACE 2 with your actual field id and "post_tag" with your custom taxonomy
        wp_set_object_terms($post_id, explode(",", $entry[2]), "post_tag");
    
        //REPLACE 3 with your actual field id and "activities" with your second taxonomy
        wp_set_object_terms($post_id, explode(",", $entry[3]), "activities");
    }

    It's perfect for a single form, but I have several others where I need to do the same.

    Posted 14 years ago on Monday October 25, 2010 | Permalink
  2. Lee Hord
    Member

    Apologies, I figured it out...

    add_filter("gform_post_data", "empty_tags", 10, 2);
    function empty_tags($post_data, $form){
    
        $post_data["tags_input"] = null;
        return $post_data;
    }
    
    add_filter("gform_post_submission", "insert_custom_taxonomies", 10, 2);
    function insert_custom_taxonomies($entry, $form){
    
        $post_id = $entry["post_id"];
    
        wp_set_object_terms($post_id, array('tag'), 'custom_tag', true );
    }
    Posted 14 years ago on Monday October 25, 2010 | Permalink