Gravity Forms taxonomy fix

<?php
//Tag to Taxonomy - A fix for gravity forms

function hyp_tag_to_taxonomy( $form ){
$id = $form['post_id'];
$raw_tag_list = $form['12'];
$tag_array = explode(',', $raw_tag_list);

foreach ($tag_array as $tag){
wp_set_object_terms( $id, $tag, 'collective',true);
}
}

add_action( 'gform_post_submission', 'hyp_tag_to_taxonomy' );

?>

12 Comments

You must be logged in to post a comment.


  1. you give an example? thanks


  2. Suppose, php conditional or another action hook


  3. is possible, confirming the "value" only when the post is published?


  4. excellent tutorial, thanks Adam, you saved my life.


  5. Thanks Greg,

    feel free to store your snippets here, the site is fully backed up and will be here for a long time. I use it every day to grab code for my every day dev job.


  6. You can pass wp_set_object_terms an array of terms, so all you need is

    function hyp_tag_to_taxonomy( $form ) {
    $id = $form['post_id'];
    $tag_list = $form['8'];
    wp_set_object_terms( $id, $raw_tag_list, 'species',true);
    }
    add_action( 'gform_post_submission', 'hyp_tag_to_taxonomy' );



  7. Check out this: http://codex.wordpress.org/Custom_Taxonomies

    You need to have an existing taxonomy for this to work. Also, gravity forms has released many new version since I wrote this code so it way not have the same effect.


  8. Hi Adam,
    This has to be some special work but unfortunately I could get it to work for me OR may be am too .. for this nice piece of code to make it work for me. I did my best to follow the instructions but failed to follow them on line 5, where it says
    `5) Change the 'my_taxonomy' argument to the name of your custom taxonomy`
    I will really appreciate if you could let me know how to make it work.


  9. OK, thank you


  10. I suppose you could create a php loop that goes through all the gravity forms based on id.
    Where the $form['12']; is for form id 12 maybe somewhere within that function. I wish I could help more but I only used this snippet once, a while ago.


  11. Hi,

    great fix!
    But how can is use this for multible forms?