Show ACF field from custom taxonomy and display on the single template


I have a custom post type called products, which I have attached a custom taxonomy called Product Categories.

On each of the Product Categories, I have used Advanced Custom Fields to add fields such as product category colour, logo etc.

Initially, I’m trying to display the Product Category colour as a background colour for all of the products that fall inside that specific Product Category.

I’ve tried using the same method as I used to display the colour on the actual Product Category page (taxonomy-product_category.php), by adding this to the top of the page:

// get the current taxonomy term
$term = get_queried_object();

// vars
$category_colour_primary = get_field('category_colour_primary', $term); 

and then referencing it later on like this:

<div class="container-flex" style="background-color:<?php echo $category_colour_secondary; ?>;">

This works great on each of the Product Category pages, but doesn’t seem to work on the single page template (single-products.php).

I feel I need to get the name (or terms?!) of the current product’s taxonomy and then display them as usual…

I’ve come to a bit of a dead end and I’m unsure what I need to try next…

Can anyone point me in the right direction? I feel I’ve tried a million things, but can’t quite get my head around it. Thanks for looking!

, , , Shaun Taylor 3 years 2020-07-10T07:10:27-05:00 0 Answers 62 views 0

Leave an answer