I have a custom post type (item) with multiple custom taxonomies (item_category_A, item_category_B, etc.) I’d like to retrieve custom taxonomy terms of the current item from item_category_A, also make them clickable. My code retrieves the correct terms, but then using get_term_link() retrieves a url, looking like sitename.com/item_category_B/category_A_term_slug . What am I doing wrong? My code looks like this:

function get_item_category_A(){

   $item_cat_A = get_the_terms(get_the_ID,'item_category_A');

   echo '<a href="' . esc_url(get_term_link($item_cat_A[0]->slug,$item_cat_A[0]->taxonomy)).'">'.esc_html($item_cat_A[0]->name).'</a>';

}

Still, when I run the function, it returns the url than points to the correct term in the incorrect taxonomy (sitename.com/item_category_B/category_A_term_slug).

Read more here: get_term_link() returns incorrect url


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: