抓住所有的贴子标签,在上面循环。如果它被pattern match, 检查是否等效author_tax
术语存在。如果没有,请创建它。
现在可以构建两个堆栈:一个用于author_tax
附加到帖子的条款,以及post_tag
\'要删除的。
$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\' );
要么在所有帖子的foreach/while循环中弹出此消息,要么对其进行批处理。有了700,你应该能够尽可能地保持直线跑
increase the timeout.
此代码未经测试。先备份!
Update: 因为这是一次性的,所以只需创建一个文件import.php
在WordPress安装文件夹中,然后在第一行加载WordPress:
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
}
从浏览器中点击该脚本(&A);等待
I would run a test with just one post to start & check everything works.