How do I get the registered taxonomy terms inside archive-play.php
-
Hi I need help with displaying the registered taxonomy terms inside archive-play.php for each of the ‘game play’. Currently it is displaying all the terms associated on that page. This is specific to only the terms under ‘Model’ and ‘Leagues’ in blue link.
The page I need help with: [log in to see the link]
-
You’ll need to remove the maintenance mode before I can see anything. Either that or a screenshot would work too.
Are “game play”, “model”, and “leagues” all 1 taxonomy or 3?
hello, ‘model’ and ‘leagues’ are taxonomies
here is a screenshot: https://ibb.co/tztDBSQ
Can you provide the contents of your archive-play.php file? I’d like to check on potential code being used for this.
<?php get_header(); /* template name: Plays */ $term = get_queried_object(); $image = get_field('category_image', $term); ?> <div class="section-02 pg-header"> <div class="container"> <div class="row"> <div class="col-md-2"></div> <div class="col-md-8"> <div class="row"> <div class="col-md-12 text-center"> <h1 style="font-size: 36px;"> Filter by league </h1> </div> <!--<div class="col-md-12"> <div class="alert alert-danger alert-dismissible fade show" role="alert"> Going Live Today via Zoom 3:45pm PST <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> </div>--> </div> </div> <div class="col-md-2"></div> </div> </div> </div> <div class="section-10 league-picks"> <div class="container"> <div class="row"> <div class="col-md-1"></div> <div class="col-md-10"> <div class="row"> <div class="col-md-12"> <div class="scrollmenu"> <ul> <?php $taxonomies = get_terms( array( 'taxonomy' => 'leagues', 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 1, ) ); foreach( $taxonomies as $category ) { if( $category->parent == 0 ) { $cat_id = $category->term_id; $logos = get_field('logo', 'term_' . $cat_id); //for image return format: Image Array $logo = $logos['sizes']['thumbnail']; //default WP image sizes: thumbnail, medium, large if ($logo) { echo '<li>'; echo '<img src="'; echo $logo; echo '" class="w-25 mr-4">'; echo '<a href="'; echo get_term_link( $category->term_id ); echo '">'; echo $category->name; echo '</a>'; echo '</li>'; } } } ?> </ul> </div> </div> </div> <h3 class="text-center picks-subtitle"> Today's Picks </h3> <?php if( have_posts() ): while( have_posts() ): the_post();?> <div class="row pick-row"> <div class="col-md-4 valign"> <div class="row"> <div class="col-md-6 col-6 pb-4"> <p class="pick-date"><b><?php the_field('date');?></b></p> <h2> <?php the_title();?> </h2> </div> <div class="col-md-6 col-6 pb-4"> <div class="model-league"> <p> <b>Model</b> </p> <?php // Get the taxonomy's terms $terms = get_terms( array( 'taxonomy' => 'system', 'hide_empty' => true, ) ); // Check if any term exists if ( ! empty( $terms ) && is_array( $terms ) ) { // Run a loop and print them all foreach ( $terms as $term ) { ?> <a href="<?php echo esc_url( get_term_link( $term ) ) ?>"> <?php echo $term->name; ?> </a><?php } } ?> <p> <b>League</b> </p> <?php // Get the taxonomy's terms $terms = get_terms( array( 'taxonomy' => 'leagues', 'hide_empty' => true, ) ); // Check if any term exists if ( ! empty( $terms ) && is_array( $terms ) ) { // Run a loop and print them all foreach ( $terms as $term ) { ?> <a href="<?php echo esc_url( get_term_link( $term ) ) ?>"> <?php echo $term->name; ?> </a><?php } } ?> </div> </div> </div> </div> <div class="col-md-6"> <div class="row picks-details"> <div class="col-md-3 col-6 pb-4"> <h2> Selection </h2> <span> <?php the_field('selection');?> </span> </div> <div class="col-md-3 col-6 pb-4"> <h2> Odds </h2> <span> <?php the_field('odds');?> </span> </div> <div class="col-md-3 col-6 pb-4"> <h2> Stake </h2> <span> <?php the_field('stake');?> </span> </div> <div class="col-md-3 col-6 pb-4"> <h2> Units </h2> <span> <?php the_field('units');?> </span> </div> </div> </div> <div class="col-md-2 pb-4 valign text-center text-md-right"> <a class="btn btn-main" href="<?php the_permalink();?>""> Details </a> </div> <div class="col-md-12"> <hr> </div> </div> <?php endwhile; else: endif;?> </div> <div class="col-md-1"></div> <div class="col-md-12 text-center" style="padding: 2rem 0rem 8rem 0rem;"> <a class="btn btn-main" href="/rbbapp/play_archive/archive/">View Results</a> </div> </div> <div class="row pagination"> <div class="col-md-12 text-center"> <?php global $wp_query; $big = 99999999; echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages ) ); ?> </div> </div> </div> </div> <?php get_footer(); ?>
Looks like you’re using
get_terms()
which is meant to fetch term information from the taxonomy as a whole, not limited to the terms associated with a given post.You’re going to want to switch over to using https://developer.www.ads-software.com/reference/functions/get_the_terms/ for the spots around line 107 and 134.
Thanks for the suggestion. I dug some more and this solution worked for me to display the taxonomy for each post inside the archive page:
- <?php echo get_the_term_list( $post->ID, ‘leagues’, ‘<li class=”tax_item”>’, ‘, ‘, ‘‘ ) ?>
Yay! Glad you got this worked out.
Let us know if you need anything else.
- The topic ‘How do I get the registered taxonomy terms inside archive-play.php’ is closed to new replies.