Grab all the post tags and loop over them. If it’s deemed an “author” by a pattern match, check to see if the equivalent author_tax
term exists. If not, create it.
Now you can build two stacks: one for author_tax
terms to append to the post, and another for post_tag
‘s to be removed.
$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' );
Either pop this in a foreach/while loop for all posts, or batch it up. With 700, you should be able to get away with a straight run so long as you can increase the timeout.
This code is not tested. Backup first!
Update: Since this is a one-time thing, just create a file import.php
in your WordPress install folder, and then load WordPress in on the first line:
require './wp-load.php';
ini_set( 'max_execution_time', 300 );
$posts = get_posts( 'posts_per_page=-1&fields=ids' );
foreach ( $posts as $post_id ) {
// Code from above
}
Hit that script from your browser & wait! I would run a test with just one post to start & check everything works.