Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<?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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
Coolio. Thank you very much BigBagel. I'm kind of very much new to WP, and it seems as if the platform is very flexible with what can be done. Just one quick question, can I place this inside of a function with an 'init' action, or would that be unnecessary? –  Roc Apr 28 '13 at 15:36
    
Since you're altering the results of another plugin, you'll probably want to use the appropriate action and priority to make sure your code is called after the other plugin's code. –  BigBagel Apr 28 '13 at 19:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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