I have a magazine like post structure like so:
Parent -> Sub category -> Article.
The parent is the issue, the sub categories are the sections within the magazine like news and interviews etc and then the articles are within those sections.
I have background images which are associated with the sub category and then articles within that sub category inherit the background image. Code in single.php which retrieves the background image from its sub category hence  not its top level parent .
<?php $category = get_the_category(); $hierarchy = array_reverse( get_ancestors( $category->term_id, 'category' ) ); $hierarchy = $category->term_id; ?> <body style="background:url('<?php echo z_taxonomy_image_url($hierarchy); ?>')" class="background-img">
For the most part this works just fine, however on a few articles the background image doesn't show. I have breadcrumbs showing the category structure and the posts that work show the full
parent -> sub category -> post name structure, however on the ones that don't work just shows
parent -> post name. There is the standard wordpress breadcrumbs and meta info at the bottom which always displays the correct heirachy for the post which is why I am confused.
How come some posts how their correct heirachy whilst others don't?
My permalink structure is
You can check the bug out here post with background and proper taxonomy at the top