最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - get taxonomy list in a page in the wordpress

matteradmin11PV0评论

I have this code in a page in the WP for show new taxonomy

<?php
  $terms = get_terms(array(
  'hide_empty' => 'false',
  'orderby'    => 'name',
  'order'      => 'ASC',
  'taxonomy'   => 'mylist' 
 ));

  foreach  ($terms as $category) {
      echo '<div class="col-ms-4">';
         echo '<div class="category-list">';
             echo '<a href="' . get_category_link( $category->term_id ) . ' "><div class="image_wrapper is-image list-image">'. do_shortcode(sprintf('[wp_custom_image_category term_id="%s"]',$category->term_id)). '</div></a>' ;
             echo '<div class="image-category"><h2 class="title-category"><a href=" ' . get_category_link( $category->term_id ) . ' "> '.$category->name.' </a></h2></div>';
             echo '<div class="category-count"><a>' . $category->count . '</a></div>';
         echo '</div>';
      echo '</div>';
} ?>

but this is not working. Do you have an idea to display new taxonomies on the WordPress? Using this code

I have this code in a page in the WP for show new taxonomy

<?php
  $terms = get_terms(array(
  'hide_empty' => 'false',
  'orderby'    => 'name',
  'order'      => 'ASC',
  'taxonomy'   => 'mylist' 
 ));

  foreach  ($terms as $category) {
      echo '<div class="col-ms-4">';
         echo '<div class="category-list">';
             echo '<a href="' . get_category_link( $category->term_id ) . ' "><div class="image_wrapper is-image list-image">'. do_shortcode(sprintf('[wp_custom_image_category term_id="%s"]',$category->term_id)). '</div></a>' ;
             echo '<div class="image-category"><h2 class="title-category"><a href=" ' . get_category_link( $category->term_id ) . ' "> '.$category->name.' </a></h2></div>';
             echo '<div class="category-count"><a>' . $category->count . '</a></div>';
         echo '</div>';
      echo '</div>';
} ?>

but this is not working. Do you have an idea to display new taxonomies on the WordPress? Using this code

Share Improve this question edited Feb 8, 2019 at 15:26 omid chahardoli asked Feb 8, 2019 at 10:27 omid chahardoliomid chahardoli 191 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The functions such as get_categories are unique to the post category taxonomy. "Category" is a taxonomy term. If you register your own taxonomies, you need to use get_terms which has similar parameters to your get_categories function.

$terms = get_terms(array(
   'hide_empty' => false,
   'orderby'    => 'name',
   'order'      => 'ASC',
   'taxonomy'   => 'your-taxonomy' 
));
Post a comment

comment list (0)

  1. No comments so far