I have a situation where i have about 5000 imported records in a custom post type (travel) with a taxonomy category (country). Since i import from several different locations and each source seems to use a different description for some countries i want to update the term reference of that post to a uniform description.
So say the taxonomy ‘country’ has, amongst others, these values:
+---------+-------------+
| term_id | name |
+---------+-------------+
| 1248 | Zuid Afrika |
+---------+-------------+
| 3845 | zuid-afrika |
+---------+-------------+
I want to update the term reference to ‘country’ that has a duplicate in each ‘travel’ post to a new defined id.
$terms = array(
'3845' => '1248'
);
$args = array(
'posts_per_page' => -1,
'post_type' => 'travel',
'post_status' => 'publish'
);
global $post;
$my_query = new WP_Query($args);
if($my_query->have_posts()){
while ($my_query->have_posts()) : $my_query->the_post();
/*
This is the part where i get lost, what i want is something like this, but this doesn't work
*/
if(in_array($post->term_id,$terms){
update term reference with value $terms[$post->term_id];
}
}
endwhile;
wp_reset_query();
}
Any help would be really appreciated because i’m pretty much stuck right now
Edit:
I don’t want to delete the taxonomy categories because this scripts will run after the imports so if the duplicates are deleted they will be imported straight back but with a different term id