I have created a function that allows me to display the next/previous category, by order of their position. This is working fine, the problem I am having is getting ACF fields to display specific to each category.
I currently have a colour picker ACF field for every category - which is different for each one, this is set to display on each link. At the moment, the ACF field is only bringing in the hex value from the current category that is being viewed, as opposed to the next/previous ones.
function next_prev_cat() {
$this_taxonomy = get_queried_object();
if (is_category()) {
$taxonomies = get_categories();
}
if (is_tag()) {
$taxonomies = get_tags();
}
foreach ($taxonomies as $position => $tax):
if ($this_taxonomy->term_id == $tax->term_id):
$next_tax = $position + 1;
$prev_tax = $position - 1;
break;
endif;
endforeach;
$showPrev;
$showNext;
if ($prev_tax < 0) {
$prev_tax=count($taxonomies) - 1;
$showPrev='';
} else {
$prev_tax;
$showPrev = $taxonomies[$prev_tax]->name;
}
if ($prev_tax == count($taxonomies)-2) {
$next_tax = 0;
$showNext = '';
} else {
$showNext = $taxonomies[$next_tax]->name;
}
$prevLink = get_term_link( $taxonomies[$prev_tax] );
$nextLink = get_term_link( $taxonomies[$next_tax] );
?>
<div class="area-links">
<a style="border:1px solid <?php the_field('brand_colour', $tax); ?>" href="<?php echo $prevLink;?>"><?php echo $showPrev; ?></a>
<a style="border:1px solid <?php the_field('brand_colour', $tax); ?>"href="<?php echo $nextLink;?>"><?php echo $showNext ?></a>
</div>
<?php
}
$tax
to the function to fetch the field value - and that is simply going to be the last taxonomy term your foreach loop iterated over.