Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $post_tags = get_the_terms( $post_id, 'post_tag' );
- $authors =
- $remove = array();
- foreach ( $post_tags as $post_tag ) {
- if ( preg_match( '/^[[0-9]+] *([^,]+), *(.+)$/', $post_tag->name, $match ) ) {
- $fullname = "$match[2] $match[1]";
- if ( $term = get_term_by( 'name', $fullname, 'author_tax' ) ) // Already exists
- $authors[] = ( int ) $term->term_id;
- elseif ( ! is_wp_error( $term = wp_insert_term( $fullname, 'author_tax' ) ) ) // Create new author tax term
- $authors[] = ( int ) $term['term_id'];
- $remove[] = ( int ) $post_tag->term_id;
- }
- }
- $authors && wp_set_object_terms( $post_id, $authors, 'author_tax', true /* Append terms */ );
- $remove && wp_remove_object_terms( $post_id, $remove, 'post_tag' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement