I have a custom taxonomy (expertise_taxonomy) for a custom post type (case_studies) and an archive template for it (taxonomy-expertise.php). My problem is that on a subcategory page I need to echo its parent category name at the top of the page and its permalink (think breadcrumb). I'm able to get the parent category ID but can't get the name permalink. It looked as though get_ancestors
was the right direction but all I get is an empty array.
Here's the pertinent part of my template code:
<?php
$taxonomy = get_query_var('taxonomy');
$termId = get_queried_object()->term_id;
$title = get_field('expertise_deliverables_title', $taxonomy . '_' . $termId);
$content = get_field('expertise_deliverables', $taxonomy . '_' . $termId);
$parent = get_queried_object()->parent;
?>
<?php if ( have_posts() ) : ?>
<p><a href="/expertise">Expertise</a> |
<!-- This is where the parent permalink should go -->
<a href="/">
<!-- This is where the parent ID is echoed instead of the name -->
<?php echo $parent; ?>
</a> | <?php echo str_replace('Expertise: ','', get_the_archive_title()); ?></p>
An example desired output would be while looking at the 'Apple' child category archive page it would have its parent category 'Fruit' in the breadcrumb like so:
Expertise | <a href="/fruit">Fruit</a> | Apple
Any help would really be appreciated!