The problem is this. Created a Custom Post Type (name = film). And all posts are displayed, respectively, on the page www.site.ru/film. I also created custom taxonomies for these headings: year and director. So, how can I see the names of the headings (without links) and the label next to the goods in the file archive-film.php? Ie, for example, in my Director’s section there is “Boris Khlebnikov”, we need to bring out the name - Boris Khlebnikov and the Label that WP himself creates (boris-hlebnikov in my case). I searched in Google, but there is other information.

Post type creation code

function film_create_post_type() { register_post_type( 'film', array( 'labels' => array( 'name' => __( 'Фильмы' ), 'singular_name' => __( 'Фильм' ) ), 'supports' => array('title','editor','thumbnail'), 'public' => true, 'has_archive' => true, ) ); register_taxonomy( 'year', 'film', array( 'label' => __( 'Год ' ), 'rewrite' => array( 'slug' => 'works' ), 'hierarchical' => true, ) ); register_taxonomy( 'producer', 'film', array( 'label' => __( 'Режиссёр' ), 'rewrite' => array( 'slug' => 'works' ), 'hierarchical' => true, ) ); } 

Also code achive-film.php

  <?php $args = array( 'post_type' => 'film', 'posts_per_page' => -1 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="nearest-slide "> <div class="nearest-slide__photo"> <a href="<?php echo the_permalink();?>"> <?php echo the_post_thumbnail()?> </a> </div> <div class="nearest-slide__title"> <a href="<?php echo the_permalink();?>"> <h3><?php the_title()?></h3> </a> </div> <div class="nearest-slide__line"></div> <div class="nearest-slide__paragraph"> <p><?php echo get_field("film_small")?></p> </div> <div class="nearest-slide__bottom"> <div class="nearest-slide__date"><?php echo get_the_date('dmY')?></div> <div class="nearest-slide__link"> <a href="<?php echo the_permalink();?>"> <svg class="longarrow" width="18" height="18"> <use xlink:href="#longarrow"></use> </svg> </a> </div> </div> </div> <?php endwhile;?> 
  • Show your code. - KAGG Design
  • Added code in post - Daniel qwaqwaqwa
  • This is good, but it is more important to see the output code - archive-film.php - KAGG Design
  • I added this code too ) But here the standard output cycle is Daniel qwaqwaqwa

1 answer 1

Insert loop inside loop

 $terms = wp_get_post_terms( get_the_ID(), 'producer' ); echo 'Режиссер:' . $terms[0]->name; echo ' Слаг:' . $terms[0]->slug; 
  • Thanks, but how to do it if you need to outside the loop? - Daniel qwaqwaqwa
  • That's why I asked for the code in order to understand where you want to output it. Outside the loop, you need to know the post id, whose terms should be displayed. Where does this post come from? Show the code how you display this post outside the loop - KAGG Design
  • You all correctly described. I need to bring it out Slug and in a loop. But outside of the loop there is also a place where I need to display all all arbitrary taxonomies. First one, then the other - Daniel qwaqwaqwa
  • get_terms () wp-kama.ru/function/get_terms - KAGG Design
  • Thank you very much, I did everything - Daniel qwaqwaqwa