categories - get taxonomy list in a page in the wordpress

admin2025-06-03  6

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' 
));
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748931073a314920.html

最新回复(0)