I am using the following code to display a list of categories in a custom taxonomy, except the URL returns only the current page URL.

<?php $category_ids = get_all_category_ids(); ?>
  $args = array(
     'orderby' => 'slug',
     'parent' => 0,
    'taxonomy' => 'servicecats',
    'hide_empty' => 0
$categories = get_categories( $args );
foreach ( $categories as $category ) {
      $imgurl = z_taxonomy_image_url($category->term_id); 
      echo '<li><img src="'. $imgurl . '"/><a href="' . get_category_link( $category->term_id ) . '" rel="bookmark">' . $category->name . '' . '' . $category->description . '</a></li>'; 

I have read in other topics I should be using get_term_link but this gave me an error, also changed get_categories to get_terms and my categories disappeared off the screen. How can I get this URL to link to the category please?

  • As you found in your answer, you have to use get_term_link() because it's a custom taxonomy. One debugging tip though: it probably didn't return the current page URL, it likely returned nothing - your browser interprets that as a link to the current page. Debugging tip is to check your HTML source for clues; you'd probably see <a href=""> in this case
    – Tim Malone
    May 4 '16 at 21:28

I changed get_category_link to:

esc_attr(get_term_link($category, 'servicecats'))

Thanks to this site

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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