[Resolved] How to output taxonomy custom fields in view?
This thread is resolved. Here is a description of the problem and solution.
Problem:
The issue here is that the user has a taxonomy that has a color picker and wanted to use that taxonomy color for the background color when listing their post.
Solution:
In this case you will need to use a nested view.
You will create a taxonomy view that will list your taxonomy, then use the fields and views button to add the appropriate fields to the view output.
Next add a query filter for the Taxonomy term and set it to "Set by the current post". See Screenshot
Finally all you need to do is to add this Taxonomy view to the view that is listing your posts.
The taxonomy view should be added to the div in the parent view that will be listing out the posts .
In the "Term Fields" section I've created a new group of custom fields for post categories:
- Category Color (color picker)
- Category Icon (image)
So that each category has its own icon and color.
I have a view that outputs a grid of all posts from different categories. Question: how to apply the respective "Category Color" value as a background color for a post in the grid and how to output the respective "Category Icon" for each post in the grid as well? In the view builder when I click the button "Fields and views", I can't find the fields that I created.
Like I mentioned above, I need to output a grid of posts, not categories. Hence this is a simple view, not a taxonomy view.
If I use the taxonomy view I will only get the list of categories, not posts. Which I don't need.
So, my questions still stands: in the post grid (simple view) how to output any custom field related to category.
As in:
- post 1 (title, category name, category color, category icon)
- post 2 (title, category name, category color, category icon)
- etc
Great! That works!
BUT:
The nested taxonomy view comes with the tags in code: <form> and <div> with a lot of attributes in each of them.
What I need is a pure custom field value taken from the taxonomy view and placed into the post view.
Schematically:
<post view>
<post style="background-color: [taxonomy-custom-field-value]">
...
</post>
</post view>
In other words, in the post view I can't use custom fields from taxonomy view because it comes only wrapped in the div of taxonomy view.
Is there any way I could use pure custom term fields values?