Make {acffield=field_name} work in taxonomy terms

We can currently use {acffield=field_name} to get ACF field values inside posts and post queries, which is great. It would be even better if we can also use this functionality inside term archives and taxonomy queries.

For example:

  • I can add an ACF color picker to all posts of a post type, allowing the user to select a color for each post. For certain blocks in the post template, I add a static attribute called ‘style’ and a value like ‘background-color:{acffield=field_name}’ or ‘color:{acffield=field_name}’. This works fine to show those elements in the selected color. It also works in query template blocks, for example on a page with an overview of the latest posts.

  • If I want to do the same for my taxonomy terms, it does not work. The {acffield:field_name} defaults to the post ID as the source. In taxonomy related queries, it should default to the term ID.

I just found out that we can’t even target each term via CSS, as they do not have a unique ID assigned automatically, and we cannot add one via attributes (Make all dynamic data available for Attributes and Tooltips). I have tried with a static attribute and {termquery=term_id} as well.

It seems to be impossible currently to add a different background color to each term…

Alternatively, or additionally, you could add the option to select ‘Current Term’ in dynamic attributes for both ‘WordPress’ and ‘ACF’. This should then be available in blocks under Taxonomy Terms block, and any other taxonomy-related queries.

Update: Araminta was so nice to send me a workaround for this issue:

Basically, she included an extra step where you add a background color or color to your block under the Taxonomy Terms block, in this format: var(–acffield=field_name}
Then, the format for the static attribute is like this: background-color:{acffield=field_name=taxterm}
However, I have tested this without the extra step, and it works fine with just the =taxterm added to the attribute.

Hello @Louis,

I can confirm we have used this multiple times and it works.

The only limitation we found was it didn’t work in an attribute for a Section block.

We had to use a Div block change the html tag to section and add the default Cwicly Section block attributes to it.