Changing taxonomy term by slug (wp_update_term)

What I am trying to accomplish is to update a taxonomy term name using its slug rather than the $term_id

WordPress does this by:

Read More
<?php wp_update_term( $term_id, $taxonomy, $args )  ?>

Is it possible to do this via the slug instead?

<?php wp_update_term( get_term_by( 'slug', $value, $taxonomy, $output, $filter ) )  ?>

I’ve been stuck on this for a while – but no success.

The default taxonomy terms are created by a plugin. I am creating a secondary plugin to change the taxonomy terms created by the ‘parent’ plugin.

Thanks!
Roc.

— Edit —
Should mention that I am not able to update the term by id because the taxonomy id changes based on when the plugin is activated, and if other tags exists before it can be created.

Related posts

Leave a Reply

1 comment

  1. As you hinted in your question, you could use get_term_by() to return an object or array containing the term’s id, then use it to update that term. Something like this should work:

    $your_term = get_term_by( 'slug', 'your_slug', 'your_taxonomy' );
    
    if ( false !== $your_term ) {
        wp_update_term( $your_term->term_id, 'your_taxonomy', $args );
    }
    

    References:

    http://codex.wordpress.org/Function_Reference/get_term_by

    http://codex.wordpress.org/Function_Reference/wp_update_term