Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. $post_tags = get_the_terms( $post_id, 'post_tag' );
  2. $authors =
  3. $remove = array();
  4.  
  5. foreach ( $post_tags as $post_tag ) {
  6. if ( preg_match( '/^[[0-9]+] *([^,]+), *(.+)$/', $post_tag->name, $match ) ) {
  7. $fullname = "$match[2] $match[1]";
  8.  
  9. if ( $term = get_term_by( 'name', $fullname, 'author_tax' ) ) // Already exists
  10. $authors[] = ( int ) $term->term_id;
  11. elseif ( ! is_wp_error( $term = wp_insert_term( $fullname, 'author_tax' ) ) ) // Create new author tax term
  12. $authors[] = ( int ) $term['term_id'];
  13.  
  14. $remove[] = ( int ) $post_tag->term_id;
  15. }
  16. }
  17.  
  18. $authors && wp_set_object_terms( $post_id, $authors, 'author_tax', true /* Append terms */ );
  19. $remove && wp_remove_object_terms( $post_id, $remove, 'post_tag' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement