Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Save linked taxonomies for a sinle field
- */
- function save_taxonomy_field( &$field, $entry, $taxonomy ) {
- if ( array_key_exists( 'type', $field ) && $field['type'] == 'checkbox' ) {
- $term_ids = array();
- foreach ( $field['inputs'] as $input ) {
- $term_id = (int) $entry[ (string) $input['id'] ];
- if ( $term_id > 0 )
- $term_ids[] = $term_id;
- }
- if ( !empty ( $term_ids ))
- wp_set_object_terms( $entry['post_id'], $term_ids, $taxonomy, true );
- } else if ( array_key_exists( 'type', $field ) &&
- ($field['type'] == 'text' || $field['type'] == 'multiselect') ) {
- $terms = $entry[$field['id']];
- if ( !empty($terms) )
- wp_set_post_terms( $entry['post_id'], $terms, $taxonomy );
- } else {
- $term_id = (int) $entry[$field['id']];
- if ( $term_id > 0 )
- wp_set_object_terms( $entry['post_id'], $term_id, $taxonomy, true );
- }
- }
Add Comment
Please, Sign In to add comment