Skip Navigation

[Resolved] Display term field in content template

This thread is resolved. Here is a description of the problem and solution.

Problem:
Where can I display Term Fields?

Solution:
At the moment, you can display term fields on a View listing terms and on a term archive page.

There is no possibility to display them elsewhere, else how.

Relevant Documentation:
https://toolset.com/documentation/user-guides/displaying-wordpress-term-fields/

This support ticket is created 7 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Adrian 7 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#561498

Hi,

I have a custom taxonomy with a term field called "image"

I need to display that image on all the child posts of that taxonomy.

id=$parent does not seem to work... nor do I think it applies here.

I have area, which is a category-style taxonomy for Neighborhoods.
Areas have a custom field called area image.

I need to display the area image from the Area that the neighborhood belongs to, on the Neighborhood content template.

#561501

The solution to incorporate a view is not feasible, since the view gets wrapped in a bunch of divs, and I need the plain URL of the taxonomy's custom image field to be used as a background for a div in a custom post belonging to that taxonomy.

#561515
Bildschirmfoto-2015-11-04-um-19.10.47.png

At the moment, you can display term fields on a View listing terms and on a term archive page.

There is no possibility to display them elsewhere, else how.

If you need a "raw" View Output, this is not something we provide, as Views is a Data Display engine, just as the rest of the Toolset display features, but you could apply some custom code, after a careful evaluation if it will fit your need.

The Custom Code is elaborated below.

1. The following snippet produces a clean View output, or as clean as we can:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
 
function prefix_clean_view_output( $out, $id ) {
if ( $id == '375' ) {
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if ( 
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}

2. Use a Views Loop similar to the one in the screenshot

3. Step by step:

- It hooks early in the View output.
- Priority 5 is mandatory as we already do some other cleaning at priority 10.
- It only affects a View with an ID of 375, adjust acordingly if needed.
- It only affects Views with actual results: if the View matches no result, the same “No items found” or whatever you have between the wpv-no-items-found shortcode applies.
- It returns only what is between the HTML comments <!– wpv-loop-start –> and <!– wpv-loop-end –> , excluding them. Only content between those HTML comments is returned, as is.
- Notice that, with this applied to a given View ID:

- Pagination, specially AJAX pagination, will not work.
- Parametric search, specially AJAXed parametric search, will not work.
- Other future features will not work either.

So this is to be used if and only if you know what you are doing and you are going to use the View output as source for anything else.

But also notice that this only clears the View structure.

Building as example JSON inside a View output is wrong because we can not address quoting problems.

Please use this with caution.

#562510

I see. I ended up using a custom view, where I created a div with the background I needed, and then placed that inside another div and floated it.

Still would be nice if that were supported similar to how $parent is supported for parent posts.