Guest User

Untitled

a guest
May 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1.         /*
  2.          * Save linked taxonomies for a sinle field
  3.          */
  4.         function save_taxonomy_field( &$field, $entry, $taxonomy ) {
  5.             if ( array_key_exists( 'type', $field ) && $field['type'] == 'checkbox' ) {
  6.                 $term_ids = array();
  7.                 foreach ( $field['inputs'] as $input ) {
  8.                     $term_id = (int) $entry[ (string) $input['id'] ];
  9.                     if ( $term_id > 0 )
  10.                         $term_ids[] = $term_id;
  11.                 }
  12.                 if ( !empty ( $term_ids ))
  13.                     wp_set_object_terms( $entry['post_id'], $term_ids, $taxonomy, true );
  14.             } else if ( array_key_exists( 'type', $field ) &&
  15.               ($field['type'] == 'text' || $field['type'] == 'multiselect') ) {
  16.               $terms = $entry[$field['id']];
  17.               if ( !empty($terms) )
  18.                 wp_set_post_terms( $entry['post_id'], $terms, $taxonomy );
  19.             } else {
  20.                 $term_id = (int) $entry[$field['id']];
  21.                 if ( $term_id > 0 )
  22.                     wp_set_object_terms( $entry['post_id'], $term_id, $taxonomy, true );
  23.             }
  24.         }
Add Comment
Please, Sign In to add comment