I am using the get_categories() function to manually create myself a nav menu. I have a custom taxonomy I’m using called Category and I’m trying to return the link for it for my tags in the menu using the get_category_link() function.
foreach ($categories as $category) {
if ($category->parent == 0) { //Check to see it is a parent
$output .= '<li>';
$output .= '<a href="' . get_category_link($category->cat_ID) . '">' . $category->name . '</a>'; //display parent taxonomy category
}
}
But it always returns <a href="">
. I can echo out the $category->cat_ID
successfully so I know it is passing the ID into the function but I don’t know why it’s returning blank.
Am I missing something? Is it because these are custom taxonomies? They have slugs.
You need something like this for custom taxonomies:
Although you can easily add to the top of the script to get an array of all taxonomies to feed in if you wanted.