• Resolved katzw

    (@katzw)


    Hi!
    I want to show only one taxonomy term in the breadcrumb of a page, for example:
    If the transplant type is “Pediatric Allogeneic”, the below code will show it:
    `<?php global $post;
    $fact_post_id = $post->ID;
    $fact_taxonomy = ‘transplant-types’;
    the_terms( $fact_post_id, $fact_taxonomy, ‘Showing Results For: ‘, ‘ / ‘ );
    echo ‘</div>’;
    ?>`

    But it also shows each term in the taxonomy. I’m hoping there is a quick way to only show “Pediatric Allogeneic” in the breadcrumb list. I’m using WCK to create the custom taxonomy. Any ideas? Thanks so much!

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator t-p

    (@t-p)

    – Are you using a plugin for breadcrumb? Yes? Which plugin? Where did you download it from?
    – Is this a feature of your active theme? Yes? What’s the name of this theme? Where did you download it from?

    https://make.wordpress.org/support/handbook/forum-welcome/#include-as-much-information-as-possible

    Thread Starter katzw

    (@katzw)

    Hello – I got the code from this tutorial:
    https://rudrastyh.com/wordpress/terms-in-breadcrumbs.html

    I am using my own theme.

    Moderator t-p

    (@t-p)

    I’m not familiar with that code, sorry.

    I recommend asking at where you got that code so you can get support from the people who know it best.

    • This reply was modified 6 years, 10 months ago by t-p.
    Thread Starter katzw

    (@katzw)

    So I shouldn’t ask for help with WordPress code on a WordPress forum? I want to learn, and the code above is not particularly unique, I’m just declaring 2 variables and calling a default wordpress function. I feel like I’m missing something to filter the results, but the codex doesn’t include information on that.

    Moderator t-p

    (@t-p)

    Best is to ask the place you got that code from 🙂

    • This reply was modified 6 years, 10 months ago by t-p.

    Hello katzw,

    If you select only one taxonomy term for that particular page or post I think this will be works:

    <?php 
    global $post;
    $fact_post_id = $post->ID;
    $fact_taxonomy = "transplant-types";
    $Cat = wp_get_post_terms( $fact_post_id, $fact_taxonomy, array("fields" => "names"));
    echo "Showing Results For: ".$Cat[0];
    ?>

    Thanks,

    • This reply was modified 6 years, 10 months ago by Rishi Shah.
    Thread Starter katzw

    (@katzw)

    Hi Rishishah,
    Thank you so much for sending this in, however it pulls the first item in the taxonomy, not the term that was clicked. I’ll keep trying!

    Thread Starter katzw

    (@katzw)

    So I figured it out – I knew it had to be simple:

    <?php
    $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); ?>
    <p>You are viewing the following Clinical Type: <?php echo $term->name; ?></p>

    So the above gets the taxonomy and the term that was clicked in order to display it. Super simple, I just didn’t know what function to use, and maybe this helps somebody else!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Taxonomy Breadcrumb – Need to get Single Taxonomy Term, not the whole tree’ is closed to new replies.