Term color custom field as background color

I have a custom post type (trip), and a custom made taxonomy assigned to it (trip category). For the taxonomy, I added (with ACF) a color picker field (slug: szin).

I want to show all the trips in a grid (query loop), and want to show the category assigned to each trip. Now the question is, how can I use the color picker field’s value as a backgroud color for these categories? The idea is very similar to what it is on the main page of the forum:

So far I’ve tried quite a few things, all of them at the dynamic data field under background: {acf_szin}, {term_meta:szin}… so far I didn’t explore the {echo}. Is there a way to do this without some custom PHP?

Thanks!

Thank you for pointing out this thread, but it still doesn’t work for me. If I use the attribute section, and set a static backround-color: red, than it works, but backround-color: {acf_szin} or background-color: {term_meta:szin} still doesn’t work. I think the problem might be with accessing the field, as it’s a field of the taxonomy assigned to the post, and not a field of the post itself. But still, I can access the category name with no problem ({post_terms_termslug}).

need more information. I checked, it works for me with categories for posts.

And there is no need to immediately insert into the attributes, for now just display it as text.

The post type:


The taxonomy:

The custom field:

The backend:

Only the {post_terms_utazas-kategoria} seems to retrieve any values:

term_meta works but it works on the term loop query

hmmm

image

1 Like

you have 2 option give the color field to posts or just get the category id assign as Idont know color-{cat_id}

something like that in the attributes assign as class. and create a style list for each category

category1 => .color-1 => background:red
… etc

just write some simple CSS and select those category ids as class names… save time :slight_smile:

actually, it is even possible to generate those css styles dynamically with term loop
if you can figure it out :wink:

@clickfusion63 sorry, I totally missed the second-, nested loop within the post loop. I does work now for me as well, thank you so much!