• I’m trying to get the url for a custom taxonomy category term without its ID or slug, because a I want to get the taxonomy that has been queried.

    So im trying to get the url of whatever term that is associated with “x” custom taxonomy, the same way that you would get “the_category()” in a category.php file, so how can I get the url for the taxonomy.

    single_cat_title( ”, true); gets the name but not the url for that particular taxonomy term.

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
      $taxo_text = '';
      $prodcat_list = get_the_term_list( $post->ID, 'product_category', '', ', ', '' );
    
      if ( '' != $prodcat_list )
      $taxo_text .= $prodcat_list;
      ?>

    not sure if I’m doing what you are asking here, this is how I get the url of anything in the product_category custom tax

    then spit it out with

    <?php echo $taxo_text; ?>

    but obviously you could do what you want with $taxo_text… so $taxo_text behaves for my custom tax as the_category does for normal cats

    Thread Starter fgiancarlo100

    (@fgiancarlo100)

    What I mean is that when you create a category.php file, you can write “the_category();” for the h1 title. That gives you a link and the name at the same time.

    What I want to accomplish is to do the same for for the taxonomy.php file but the_category(); doesn’t work when the the taxonomy.php file is queried.

    Thread Starter fgiancarlo100

    (@fgiancarlo100)

    I tried it again and it work just like I wanted thank you very much.

    Mistake: <h1 class="title"><a href="<?php echo $taxo_text; ?>"><?php single_cat_title( '', true); ?></a></h1>

    Fix: <h1 class="title"><?php echo $taxo_text; ?></h1>

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Getting a taxonomy's term url’ is closed to new replies.