daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. add_action('gform_post_submission', 'hyp_tag_to_taxonomy', 10, 2);
  4. function hyp_tag_to_taxonomy($entry, $form){
  5.    
  6.     $post_id = $entry['post_id'];
  7.     $taxonomy = '';
  8.  
  9.     foreach($form['fields'] as $field) {
  10.         switch($form['id']) {
  11.         case 1: // enter your form ID here
  12.            switch($field['id']) {
  13.            case 12: // update to a field ID which contains a list of tags
  14.               $taxonomy = 'your-tax-name';
  15.               $tag_string = $entry[12];
  16.               break;
  17.            case 14: // update to a field ID which contains a list of tags
  18.               $taxonomy = 'different-tax-name';
  19.               $tag_string = $entry[14];
  20.               break;
  21.            }
  22.            break;
  23.         case 2: // enter your form ID here
  24.            switch($field['id']) {
  25.            case 13: // update to a field ID which contains a list of tags
  26.               $taxonomy = 'your-tax-name';
  27.               $tag_string = $entry[12];
  28.               break;
  29.            case 15: // update to a field ID which contains a list of tags
  30.               $taxonomy = 'different-tax-name';
  31.               $tag_string = $entry[14];
  32.               break;
  33.            }
  34.            break;
  35.         }
  36.        
  37.        
  38.         $tags = array_map('trim', explode(',', $tag_string));
  39.  
  40.         if(!$post_id || empty($tags))
  41.             return;
  42.            
  43.         foreach($tags as $tag)
  44.             //$post_id is defined as $id before, which not exists anywhere in this code
  45.             wp_set_object_terms($post_id, $tag, $taxonomy, true);
  46.              
  47.     }
  48.    
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top