Migrate data from Taxonomy Images to WP Term Images

I’ve worked on a few sites recently that used the Taxonomy Images plugin to add images to taxonomy terms, like categories. This plugin is quite old, and was built before WordPress added term meta support to core. It stores one large option with an array of all taxonomy term IDs with their associated image IDs, and has a bunch of weird filters for accessing the data.

This data really belongs in term meta. WP Term Images a great and simple plugin for managing these images.

The code below will migrate the Taxonomy Images data to WP Term Images. Add it to functions.php, refresh a page, then remove it.

<?php
/**
* Migrate data from Taxonomy Images plugin to WP Term Images
*
* @author Bill Erickson
* @see https://www.billerickson.net/code/migrate-taxonomy-images-to-wp-term-images
*/
function be_migrate_taxonomy_images() {
$taxonomy_images = get_option( 'taxonomy_image_plugin' );
$meta_key = 'image';
foreach( $taxonomy_images as $term_id => $image_id ) {
update_term_meta( $term_id, $meta_key, $image_id );
}
}
add_action( 'wp_footer', 'be_migrate_taxonomy_images' );
view raw functions.php hosted with ❤ by GitHub

If you want to use a different plugin, first find out the meta key it is using. Add an image to a term, then run `get_term_meta( $term_id )` to see all meta attached to that term. Find the meta key with your image, and update the `$meta_key` variable in the code above.

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk