Skip Navigation

[Resolved] How to display taxonomy term fields on a taxonomy archive page

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

Problem:
A taxonomy archive page displays posts that match the term included in the URL.

How to display custom fields from that term on the page, even when there are no posts to output?

Solution:
The Views shortcodes to output taxonomy term fields (e.g. wpv-taxonomy-field) only work in Taxonomy Views.

You can register a custom shortcode to output details of a taxonomy, include term fields, anywhere on the archive page as described below: https://toolset.com/forums/topic/taxonomy-single-view/#post-1259339

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

Our next available supporter will start replying to tickets in about 0.44 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by katjaL 5 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1259033

I would like to have a very custom taxonomy page. When clicking the taxonomy, I would like to open a page where this taxonomys title, image, description etc. what I have defined in taxonomy terms would show. I don't necessarily want to show at all the post list attached to this taxonomy - which comes as default.

How would I achieve this kind of taxonomy presentation/single view? Or is it possible even?

#1259339

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Katja

A taxonomy has built-in archive pages, e.g. a colour taxonomy has archives (of matching posts) available at site.com/colour/red/ and site.com/colour/blue etc.

What's useful here is the URL structure is set up already.

If you are not "using" these archives, i.e. you don't need to display posts at these URLs then you can take advantage of the URLs and the links created to them to display your "custom taxonomy pages" at these URLs, with or without matching posts.

"With" is the normal behaviour, but you could create a custom archive (at Toolset > WordPress Archives) and in the output section not include from the loop, i.e. so no posts are output.

Then you can output whatever fields you want to output about the taxonomy.

There is a problem here, in that the expected context for many of the Views shortcodes to output data from taxonomies, including term meta, is a taxonomy View, so they wouldn't output anything if inserted directly in the custom archive.

But this comes up often enough that I wrote a custom shortcode to output any fields from the taxonomy and its terms on an archive page:

/**
 * Register shortcode to output current taxonomy
 * for use on taxonomy archive page outside or inside loop
 * att['output'] string taxonomy | name (default) | slug | term_id | description | count | field (requres att['field'])
 * att['field'] string key
 */
add_shortcode('taxonomy', function ($atts = [], $content = null) {
 
    // provide defaults
    $atts = shortcode_atts(
        array(
            'output' => 'name',
            'field' => '',
        ),
        $atts
    );
    extract($atts);
 
    $return = '';
 
    global $wp_query;
    $obj = $wp_query->get_queried_object();
 
    if ($output != 'field') {
 
        $return = $obj->$output;
    } else {
        if (isset($field)) {
            $return = get_term_meta($obj->term_id, $field, true);
        }
    }
 
    return $return;
});

You would use it like so:

[taxonomy output='taxonomy'] -- outputs the taxonomy slug
[taxonomy] -- outputs the term name (default)
[taxonomy output='count'] -- outputs the count of results
[taxonomy output='field' field='wpcf-colour'] -- outputs a 'colour' taxonomy custom field
#1259749

Perfect, thank you so much!