这里涉及的步骤相当多,而且,您提到的5000篇帖子,这将是一项昂贵的任务,通过WordPress本身来完成。然而,以下是我想到的(I haven\'t tested this so you may wish to use it on a backup first and see if it works):
global $wpdb;
/* The ( \'from_term_id\', \'to_term_id\' ) map. */
$terms_map = array(
\'3845\' => \'1248\',
/* ... The rest of your mapping */
);
$taxonomy = \'country\';
$obj_terms = wp_get_object_terms( $post->ID, $taxonomy );
/* Loop through each object term */
foreach ( $obj_terms as $term ) {
/* See if the obj term_id is a key in $terms_map */
if ( isset( $terms_map[$term->term_id] ) ) {
/* We have a valid key. We now need the term_taxonomy_ids */
/* for both \'from_term_id\' and \'to_term_id\' */
$to_term = get_term( $terms_map[$term->term_id], $taxonomy );
$from_term_tax_id = $term->term_taxonomy_id;
$to_term_tax_id = $to_term->term_taxonomy_id;
/* Update the \'{prefix}_term_relationships\' table */
$update_res = $wpdb->update(
$wpdb->term_relationships, /* The table to update */
array( \'term_taxonomy_id\' => $to_term_tax_id ), /* Data to be updated */
array( \'object_id\' => $post->ID, \'term_taxonomy_id\' => $from_term_tax_id ), /* Where clause */
array( \'%d\' ), /* Format of the data is int */
array( \'%d\', \'%d\' ) /* Format of the where clause is int */
);
/* Finally, you may wish to update the term count for each term */
wp_update_term_count( array( $from_term_tax_id, $to_term_tax_id ), $taxonomy );
}
}
正如我所提到的,虽然这可能证明成本太高,但在这种情况下,您必须编写单独的PHP脚本并直接在数据库上工作。