Skip Navigation

[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 .

Example

<div style="background-color: [shortcode];"></div>

There should be an option on your view called "Disable the wrapping DIV around the View"

This should resolve the issue with the wrapping divs and provide a clean output for your view.

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Pavel Capcan 6 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#1140333

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.

Thanks!

#1140442

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pavel,

Thank you for contacting our support forum.

The view you are using. This is a taxonomy view correct?

If so then you should be able to use the Fields and Views button to add the shortcode for the custom field to your view.

So in a sense you should be able to do this.

< div style="background-color: [shortcode];">

Please let me know if this helps.

Thanks,
Shane

#1140571

Thank you Shane for the quick response!

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

Is it feasible?

Thank you!

#1140647

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2018-11-05 at 3.34.04 PM.png

Hi Pavel,

Yes this is possible.

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.

Please try this and let me know if it helps.

Thanks,
Shane

#1141068

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?

Thanks!

#1141358

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pavel,

There should be an option on your view called "Disable the wrapping DIV around the View"

This should resolve the issue with the wrapping divs and provide a clean output for your view.

Thanks,
Shane

#1141398
Screen Shot 2018-11-06 at 6.07.45 PM.png

It worked fine! Thank you!

The only concern that I have is how it's rendered in the code. There is a lot of line-breaks. Please see the screenshot.

The code I use for placing the nested view is:
<div style="background-color:[wpv-view name="tax_view_test"];">
[wpv-post-title]
</div>

And on the nested view's settings page I couldn't find any settings about removing these redundant spaces.

#1141538

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pavel,

Yes these empty spaces are there due to the removal of the Divs.

This would need to be something that would be improved from our side, however this should not cause any issues with your site.

Thanks,
Shane

#1141931

My issue is resolved now. Thank you!