Issue with get_the_terms() and custom taxonomies.
-
I’m trying to create a simply breadcrumb for a custom post type, whereby only a single parent and child category can be assigned to a single post, in the hope that the result is:
Help Centre > Parent > Child
There are four parent categories and several child categories in each parent.
I am using the following:
$terms = get_the_terms($post->ID, 'help-centre-category'); echo '<ul class="breadcrumb">'; echo '<li><a href="'.get_site_url().'/help-centre/">Help Centre</a></li>'; echo '<li><a href="'.get_site_url().'/help-centre/'.$terms[0]->slug.'/">'.$terms[0]->name.'</a></li>'; echo '<li><a href="'.get_site_url().'/help-centre/'.$terms[0]->slug.'/'.$terms[1]->slug.'/">'.$terms[1]->name.'</a></li>'; echo '</ul>';
My understanding was that $terms[0] was the parent and $terms[1] was the child, however this only seems to be the case for posts in two of the four parent categories, whilst the other two parent categories are generating the breadcrumb backwards, ie:
Help Centre > Child > Parent.
Am I approaching this incorrectly?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Issue with get_the_terms() and custom taxonomies.’ is closed to new replies.