Support » Plugins » Hacks » getting link to specific term?

  • Resolved cnever



    Hope I am in the correct section of the forums…

    To clarify how I understand taxonomies and terms:
    I have a custom post type called ‘tours’
    Assigned a taxonomy to the ‘tours’ called ‘genre’ and then within the genre I created what I know as ‘terms’?

    Within the taxonomy ‘genre’ I have multiple terms – I got it right to display the custom post type with the terms assigned to the custom post type and when you click on the term (which is a link, it shows a new page with all the posts that has that terms assigned to them).

    What I now want on the home page I have 4 links that I want to link to the same page that gets spit out when you click on a certain term for example:

    Post has ‘transfers’ next to it when click on that link, meaning a specific term within the taxonomy you go to a new page. How do I get that link or how do I recreate that link – because wordpress creates that specific link with a loop I am running?

    Any answers would be great I have tried:
    <?php get_term_link( $term, $taxonomy ); ?>

    looked at hierarchycan’t seem to get anything working with manually inputting the link.
    also taxonomies

    I have a hunch it has to do with get_term_link but when I use it it spits out nothing? I am sure I need to do query before it but not sure what?


Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz


    Yes, that’s the right function, it will work provided you assigned the proper values to $term and $taxonomy. No query required. If I understand your explanation correctly, you should be doing the equivalent of

    $taxonomy = 'genre';
    $term = 'transfers';
    $link = get_term_link( $term, $taxonomy );
    echo "<a href='$link'>$term</a>";

    WOW bcworkz!

    You simply rock, quick reply and it really worked perfectly final code:

    <br />
    <?php $taxonomy = 'genre';<br />
          $term = 'transfers';<br />
           $link = get_term_link( $term, $taxonomy );<br />
           // getting the specific term assigned to specific taxonomy :)?>
           <li><a href="<?php echo "$link";?>" class="main-links">

    I think were my problem came in was I used ” for echo and not “”? Or does that not matter?

    Thanks in any case really making a lot of doors open to my design now 🙂

    Just to let people know the <br/> code is not necessary (if someone was wondering) and forgot to mark this as resolved!

    Thanks again!

    If you read this bcworkz- is there a way to add you or stay in contact with you via this platform? I am sure I might need your brilliant coding help again!

    Moderator bcworkz


    Right, variables inside of single quoted strings will not get resolved, you need to use double quoted strings for variables to be resolved.

    Also with the html breaks, as you found, the only way to get html sent to the client browser from inside php code blocks is via the ‘echo’ statement. Otherwise it is essentially illegal php code.

    As for reaching me, I’m pretty regular here (just the hacks portion) so I’d probably see a question you post. In addition, by posting here, you benefit from the expertise of many people, and even more can learn from the resulting thread as well.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘getting link to specific term?’ is closed to new replies.