HI All
I've been exploring the use of custom taxonomies with Gravity Forms. I'd come across a great looking piece of code that appears to enable one to specify that a tag entered into the tags field should go to a specified custom taxonomy: http://code.hyperspatial.com/104/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' );
?>
I then put this question to Gravity Forms support: Can this be done for multiple different taxonomies across different forms on a single site, i.e.,:
(1) Can it be done for two different tag fields in a single form, with tags entered into the first tag field going to WP's default tags taxonomy, and tags entered into the second tag field going to a custom taxonomy?
(2) Can it be done across multiple different forms?
Their really helpful support came back saying:
Something like this would allow you to specify different fields to assign the tags to different taxonomies. This is a manual approach.
http://pastie.org/2565508
The problem I faced at this point was that this code doesn't allow one to differentiate between different forms whereas, in my case, I have a site with 5 forms on it and I need to take this approach across the different forms for different audiences.
Gravity Forms support responded stating I can wrap this switch in another switch for the form ID with a case for each form. The provided the following pseudo code:
switch($form_id) {
case 1:
switch($field_id) {
case 1:
// code
break;
case 2:
// code
break;
}
case 2:
switch($field_id) {
case 3:
// code
break;
case 4:
// code
break;
}
}
The problem I'm having is putting the two pieces of code together, i.e., what you can see in the pastie above and in the pseudo code immediately above.
I've asked the GF crew to help and am sure they will but, well, I'm working on a site right now and would love to have the answer right now.
Can anyone help please? I'm sure this is no problem for programmers well versed in PHP (unfortunately, I'm not yet).
Many thanks
Richard
Habib Rosyad answers:
Bassically maybe it's like this:
[[LINK href="http://pastie.org/2597198"]]pastie.org/2597198[[/LINK]]
I don't know how exactly GravityForms works since I haven't used it either, but for combining the pseudo code and the code in http://pastie.org/2565508 should go just like that. I this case you need to add 'switch' for the form id. I think the form id should go in $form variable so I use $form['id'] as switch... hope it works for you... :)
Richard comments:
Hi and many thanks Habib. Unfortunately, though, this code isn't having the desired effect.
Kind regards
Richard
Habib Rosyad comments:
Hmmm... let me summarize it:
The code in http://pastie.org/2565508 is worked for you, but the code doesn't allow one to differentiate between different forms, then there is those pseudo code that can be used to fix the code before. I applied the pseudo code, but it still doesn't work for you...
Can I verify these things:
1. Is the code still working (specify different fields to assign the tags to different taxonomies)?
or simply the code isn't work anymore as the previous one?
2. Just in case you know PHP a little can you dump the $form variable to see if $form['id'] is really exists using var_export($form)
I just notice from the source code there are some mistype in variable that actually not exists anywhere, so I got to fix of it: [[LINK href="http://pastie.org/2597458"]]http://pastie.org/2597458[[/LINK]] For the moment I think that's the problem
Fredelig answers:
Have you tried this (free) plugin?
http://wordpress.org/extend/plugins/gravity-forms-custom-post-types/