• Resolved hilj

    (@hilj)


    How can I get the term name outside of the loop?

    This gets it as a link:

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

    This without the link:

    $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'people', '', ', ', '' ) );
    echo $terms_as_text;

    But not outside loop ??

    Here’s some discussion

    Thanks for the help ??

Viewing 3 replies - 16 through 18 (of 18 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Use MichaelH’s code. The first three arguments of get_term_by are required values. And in Patrick’s code he only supplies 2.

    If you need to have links alter MichaelH’s code like so:

    $taxonomy = 'concerts';
    $queried_term = get_query_var($taxonomy);
    $terms = get_terms($taxonomy, 'slug='.$queried_term);
    if ($terms) {
      echo '<ul>';
      foreach($terms as $term) {
      	echo '<li><a href="'.get_term_link($term->slug, $taxonomy).'">'.$term->name.'</a></li>';
      }
      echo '</ul>';
    }

    thank u very much keesiemeijer

    This is brilliant, thank you. I had most of it, I was just missing one thing ??

    Out of curiosity, does anyone know how you would get this to output only the slug for the current page’s taxonomy?

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Get the term (custom taxonomy) name outside of the loop?’ is closed to new replies.