This is my first attempt – I didn’t test it thoroughly but it should be enough to get you started if you are a coder. It should create a taxonomy term for each post. It expects the taxonomy to be already existing, and doesn’t delete the categories afterwards. You can put that in functions.php of your theme, load any page or admin screen once, then remove it.
$gt_taxonomy = 'project_type';
$gt_cat = 49;
//get all posts of category x
$gt_posts = query_posts( array( 'post_type'=> 'post', 'cat'=> $gt_cat, 'nopaging' => true ) );
//creaate a new taxonomy for each post, and store the idPost -> idTax map
if( !empty( $gt_posts ) ){
foreach( $gt_posts as $gt_post ){
wp_set_object_terms( $gt_post->ID, $gt_post->post_name, $gt_taxonomy, false );
$gt_term = get_the_terms( $gt_post->ID, $gt_taxonomy );
$gt_termId = $gt_term[0]->term_id;
if( $gt_termId ) {
wp_update_term( $gt_termId, $gt_taxonomy, array(
'description' => $gt_post->post_content,
'slug' => $gt_post->post_name,
'name' => $gt_post->post_title
));
}
}
}
I have put that in a blog post so that I can change it easily if I find bugs, if anyone’s interested…
http://blog.gotofritz.net/howto/converting-categories-to-taxonomies-wordpress/
I have a similar problem from drkknght. Not exactly what fritzthecat is saying.
I have multiple subcategories in which I’d like create an “upper” level to work around my posts organization, custom taxonomies it is. So I created a parent category (with the custom taxonomy name) to all categories that I want to separate the term I want to convert to taxonomies.
So far so good, I have the function working but the wp_update_term function doesn’t seem to update the term to a new taxonomy.
Here is the function:
migrate_terms(123, 'new-taxonomy');
function migrate_terms($parent_id, $taxonomy) {
$child_terms = get_term_children($parent_id, 'category');
foreach($child_terms as $child_term) {
$term = get_term_by('id', $child_term, 'category');
$args = array(
'taxonomy' => $taxonomy
);
// remove parent because it is now useless
if($term->parent == $parent_id)
$update = wp_update_term($term->term_id, $term->taxonomy, array('parent' => 0));
// update term to new taxonomy
$update = wp_update_term($term->term_id, $term->taxonomy, $args);
}
}
The problem is right on this example:
wp_update_term(123, 'category', array('taxonomy' => 'new-taxonomy'));
It returns successfully but doesn’t change the term’s taxonomy. Any ideas?
Just got it fixed! I’m manually changing taxonomy through $wpdb. Here’s the new function in case anyone needs it:
migrate_terms(123, 'new-taxonomy');
function migrate_terms($parent_id, $taxonomy) {
global $wpdb;
$child_terms = get_terms('category', array('child_of' => $parent_id, 'hide_empty' => 0));
if($child_terms) {
foreach($child_terms as $child_term) {
$args = array(
'taxonomy' => $taxonomy
);
// remove parent because it is now useless
if($term->parent == $parent_id)
$update = wp_update_term($child_term->term_id, $child_term->taxonomy, array('parent' => 0));
// update term to new taxonomy
$wpdb->query(
"
UPDATE $wpdb->term_taxonomy
SET taxonomy = '$taxonomy'
WHERE term_id = $child_term->term_id
"
);
}
} else echo 'No child term was found';
}
cheers