I have a "author" custom field with the names of author. I want to add some new features to the site so I decided that custom taxonomies will be the best solution. So what I need to do is to get the value of the custom field and pass it to the custom taxonomy called artist. Sure I can do this manually but it is more than 1000 posts so it would be hell.

I guess the solution will be connected with wp_set_object_terms(); function, but nothing I tried worked.

Thank you for any answer.

1 Answer 1


Don't have a time to test it now but something like this should work:

// Change or add your own arguments as needed 
$args = array(
    'post_type'   => 'post', 
    'numberposts' => -1,
    'offset'      => 0
$my_posts = get_posts( $args );
if ( $my_posts ) {
    foreach ( $my_posts as $my_post ) {
        $meta = get_post_meta( $my_post->ID, '_name_of_your_custom_field', true );
        if ( ! empty( $meta ) )
            wp_set_post_terms( $my_post->ID, $meta, '_name_of_your_taxonomy');

You can wrap it in a function, throw it into your functions.php or make it a plugin. Just be sure you run it just once and not on every page load...

Use the get_posts() arguments to change which posts will be affected. For example you can take advantage of numberposts and offset to split the query into a few smaller ones if your server doesn't feel like processing 1000+ posts at once.

Good luck and let me know if you need more help with any of above.

  • I throwed it into functions.php and it works great. Thanks.
    – adam
    Commented Jan 23, 2012 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.