I cannot figure out how to get the taxonomy term name if I have the taxonomy term's ID.

This is my current code

// create a dropdown menu of the quantity taxonomy 
    array('taxonomy' => 'quantity_category', 'name' => 'productQuantity', 'hide_empty' => 0)

$quantityTerms = $_POST['productQuantity'];
$quantityTax   = 'quantity_category';

The value of $quantityTerms is not the "name" of the quantity but the ID of the quantity category. When it sets the object terms, it creates a new category called "ID#" and not inserting it into the category by name.

wp_set_object_terms( $post_id, $quantityTerms, $quantityTax, $append );
  • 5
    @JonFury, many of your questions demonstrate a complete lack of research effort - you could have answered this question for yourself by typing it's title into Google, not to mention that's it's answered in numerous other on-site questions that you would have seen had you searched WPSE. No one wants to waste their time answering questions that have been answered a hundred times before already. Please use a search engine, the WPSE search, and the WordPress codex before slapping questions on WPSE. Our community is not a search engine. – bosco Jan 1 '14 at 22:17

The function get_term_by() would allow you to get the taxonomy term name from the id.

$quantityTermObject = get_term_by( 'id', absint( $quantityTerms ), 'quantity_category' );
$quantityTermName = $quantityTermObject->name;
  • 8
    Please accept the answer if it worked for you @JonFurry. – Rachel Baker Nov 27 '13 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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