3

I need to print a specific term with its id. I get that for categories with this code:

<a href="<?php echo get_category_link(1); ?>" title="<?php echo get_cat_name(1);?>"><?php echo get_cat_name(1);?></a>

… where 1 is the id I have to print. Is there something like the following?

<?php echo get_term_link(1); ?>

or

<?php echo get_term_name(1); ?>
4

Use get_term() to get the name, slug, or description:

$term = get_term( 1, 'taxonomy_slug' );
// Name
echo $term->name;

// Link
echo get_term_link(1, 'taxonomy_slug'); 
// OR
echo get_term_link( $term ); 
  • You're welcome. Please mark this question as being answered, so it goes off the list of unanswered questions. :) – Eric Holmes Oct 31 '12 at 17:46
  • I'm sorry! I am beginner and especially my English :P:P i've marked it rigth? – federica Oct 31 '12 at 17:54
  • Beside my answer there should be a checkmark ✓ <- Click it! :D – Eric Holmes Oct 31 '12 at 17:57
  • ok! i did it :) – federica Oct 31 '12 at 18:03
6

Since WP 2.3.0, there is an API to get term's fields : get_term_field().

So, I would rather use <?php get_term_field( 'key', $term ); ?> which is pretty handy :

  • key : could be multiple : link, name, etc.
  • $term : can either be the term_id or the \WP_Term object.
  • 1
    I think this should be the selected answer. Being that the orginial question assumes you have the TERM ID, using this method only requires one line. Simple and to the point! – Brev Tiw Oct 13 '18 at 23:14

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.