Skip Navigation

[Resolved] Add images to custom taxonomy terms

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

Problem:
How to add images to taxonomy terms and display them.

Solution:
Taxonomies can have custom fields ("term meta") much like posts can. Go to Toolset > Custom Fields and create a field group for your taxonomy and add an image field to it.

When you add/edit terms to the taxonomy you can add an image.

To display them create a View to display terms of the taxonomy, and in the output section insert the image fields using the Fields and Views button to generate the required shortcodes.

0% of people find this useful.

This support ticket is created 5 years, 7 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
- 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 4 replies, has 2 voices.

Last updated by chrisB-30 5 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#1236380

Hello,

I am trying to add featured images to custom taxonomies and their child taxonomies which I will then use in various Views.
I read this post (and several others) - https://toolset.com/forums/topic/display-taxonomy-image-in-a-view/
But it relies on this plugin - https://wordpress.org/plugins/categories-images/
The plugin has not been updated in over a year so I am reluctant to add it to my site.
Is there any sort of new solution for this?

Thanks

#1236841

Nigel
Supporter

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

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

Hi Chris

You can go to Toolset > Custom Fields and add custom fields for taxonomy terms, including an image field.

So if you had a country taxonomy, for example, you could add a flag image to each country term.

Then if you have a View which lists the terms of the taxonomy you can simply output the the image using a types shortcode that you generate with the Fields and Views button in the output of the View.

No other plugins required, I'm not sure what the issue is.

You may find issues outputting the field outside of the context of a taxonomy View (e.g. a taxonomy archive), but if that's the case I can help get that working, let me know.

#1237021

Yep, that's the right way to do it! I guess I thought there was some advantage to wordpress actually recognizing it as a "featured image" - but there isn't.

I set up what you described but I am having trouble with the filtering.

I want to show all child taxonomies of a specific parent - on all the child archive pages under that parent.

I have Archive "Locations" with child locations like this:

Latin
Brazil
Cuba
Colombia

Asian
China
Philippines
Thailand

Etc

How do I set the filter in the view so that each child country ONLY shows the other countries in that region (Latin, Asian etc)

As a special bonus - is there a way to tell toolset NOT to show the current country in the view?

PS

I see in the taxonomy parent filter I can set "Parent is: (Latin, Asian, etc)"
But then I would have to create Elementor templates for all of Parent Locations which I would like to avoid if possible.

Any ideas??

Thanks

Here is my staging site - hidden link
You can see the view grid at the bottom of the page

#1237097

Nigel
Supporter

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

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

I can't see how to set this up without resorting to some custom code.

In this case I came up with the following shortcode to return sibling terms (i.e. have the same parent term as the current archive term) as a comma separated list.

You can then provide that list as a shortcode attribute to set the terms for a taxonomy View to determine what to output for them.

So, you can register a [siblings] shortcode like so:

add_shortcode('siblings', function () {
 
    global $wp_query;
    $obj = $wp_query->get_queried_object();

    if ( $obj->parent == 0 ) {
        return '-1';
    } else {

        $terms = get_terms(
            array(
                'taxonomy'  =>  $obj->taxonomy,
                'parent'    =>  $obj->parent,
                'exclude'   =>  $obj->term_id
            )
        );

        $term_array = wp_list_pluck( $terms, "term_id");
        return implode( ",", $term_array );
    }
});

Register that shortcode for use as 3rd party shortcode arguments at Toolset > Settings > Front-end Content.

Now create or edit a custom archive for your country taxonomy. This will show posts for that country.

Somewhere on the page where you want to display these sibling countries insert a View using a shortcode that sets the "terms" attribute with the new siblings shortcode, e.g.

[wpv-view name="other-countries-with-same-parent" terms="[siblings]"]

This View is a taxonomy View (to display terms of the country taxonomy) and includes a Taxonomy Term Filter Taxonomy term ID is set by the shortcode attribute "terms".

Design the output of the View as required (you'll probably want to remove the "No items found" text for when visiting a parent archive (e.g. "Asia").

#1237210

Perfect. You are a Toolset genius!