Forums

[resolved] Get the term name and url by ID (8 posts)

  1. Machi
    Member
    Posted 1 year ago #

    Hi there,
    I'm trying to find a solution for this:
    I'm using custom taxonomies with a few entries (terms) and I'd like to display names and links (to term's page) by their ID. Something like
    <?php echo get_category_link(id); ?>
    only with terms, the same for name.

    Is there a way how to do this?

    Thanks

  2. MAS
    Member
    Posted 1 year ago #

    <?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ', '' ); ?>

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

  3. Machi
    Member
    Posted 1 year ago #

    Hi, thanks for the reply, unfortunately I forgot to mention that I have to do this outside the loop with any term.

    Let me explain... I need a static headline + link (separately) with term's name (headline) and term's url (link). I need to display any term by ID, for example something like <?php echo get_term_name(10); ?> would display a name of term with ID 10, the same with link.

    Thanks a lot...

  4. MAS
    Member
    Posted 1 year ago #

    for url use it get_term_link( $term, $taxonomy )

  5. Machi
    Member
    Posted 1 year ago #

    Oh, where did this function come from? :O Amazing...
    <?php echo get_term_link($term,$taxonomy); ?> works awesome

    The only thing left is the name of the term I guess... get_term_name doesn't exists... it can be done with <?php wp_list_categories('taxonomy=...&include=id'); ?> but this includes a link to, that's a problem for me...

    Thanks!

  6. MAS
    Member
    Posted 1 year ago #

  7. Machi
    Member
    Posted 1 year ago #

    Oh, awesome, you're a genius :)

    This works:
    <?php $array = get_term_by('id', $id, $taxonomy, 'ARRAY_A'); ?><?php print_r($array[name]); ?>

  8. MAS
    Member
    Posted 1 year ago #

    you are welcome. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags