这将获取所有带有$old\\u tax的帖子,将条款从$old\\u tax复制到$new\\u tax,然后为这些帖子设置$new\\u tax条款。
<?php
function convert_tax($old_tax, $new_tax) {
$pages = get_posts(array(
\'post_type\' => \'post\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => $old_tax,
\'operator\' => \'EXISTS\'
)
)
));
foreach($pages as $post) {
$terms = get_the_terms( $post->ID, $old_tax );
$term = array();
foreach( $terms as $t ) {
if( get_term_by( \'name\', $t->name, $new_tax ) == false ) {
wp_insert_term( $t->name, $new_tax, $args = array() );
wp_set_post_terms($post->ID, array(intval($t->ID)), $new_tax );
}
}
}
}
convert_tax(\'policy_area\', \'topic\')
?>