0

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

1 Answer 1

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' 
));
4
  • I edited the above code but did not work and did not display the categories. where is the problem from? Commented Feb 8, 2019 at 15:00
  • What is your taxonomy called? Can you post the exact code you used (update your question with the get_terms call) Commented Feb 8, 2019 at 15:03
  • my post is updated Commented Feb 8, 2019 at 15:11
  • Does it work now (you accepted my answer). If not, then can you run var_dump($terms); before the foreach loop. You should see a list of WP_Term Object. If you don't then it means the taxonomy name is wrong or that you have an error elsewhere - please check your error_log file, or make sure to turn debugging on with define('WP_DEBUG', true); in your wp-config.php Commented Feb 10, 2019 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.