Skip Navigation

[Resolved] Display Custom Taxonomy Image Retrieved from Select Field as URL Image in View

This support ticket is created 4 years, 10 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by andrewF-6 4 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1528797

Tell us what you are trying to do?
I am trying to display the associated custom taxonomy image from a taxonomy term retrieved through custom coded select drop-down field as a URL Image link.

My View is not a Taxonomy View. It is a View of a Repeating Field Group with URL, Text Field, and Select Box. The Select Box pulls its values from a Toolset Custom Taxonomy which has an Image Field. I want to display the URL with the Text Field Label and have the link displayed with the Taxonomy Image associated with the Taxonomy Select Box value retrieved from the Custom Taxonomy List.

Is there any documentation that you are following?
https://toolset.com/forums/topic/how-to-display-the-taxonomy-image/
https://toolset.com/forums/topic/display-taxonomy-image-with-view/
https://toolset.com/forums/topic/displaying-image-link-and-name-of-a-taxonomy/
https://toolset.com/forums/topic/taxonomy-images-issue/

What is the link to your site?
Site is under construction. hidden link

Thanks!

#1529389

What are the values for each option in the Select Box - term IDs?

If they are IDs, then you can use the Types field shortcode to display the image field associated with the term ID. Types field shortcode examples are available here: https://toolset.com/documentation/customizing-sites-using-php/functions/

So let's say the select box value is a term ID, and the select field slug is "term-select". Let's say the term image field slug is "term-image". To display the term field image associated with the selected term, you would do something like this in a View of the RFG:

[types termmeta="term-image" term_id="[types field='term-select' output='raw'][/types]"][/types]

If the values in the select field are not term IDs, but are term slugs, it's not as straightforward because the Types field shortcode for term fields requires an ID. You would probably need to create a View of terms filtered by term slug using a shortcode attribute in this case, and then output the image inside the term view.

Let me know if I misunderstood the request.

#1529517

Dear Christian,

I believe you understood the problem perfectly. I used custom code to retrieve the taxonomy terms in the select field.

The end user only sees taxonomy terms in the select field box.

Is there a way for me to indirectly obtain the ID? After all it is pulling the values for the select field from the list of Taxonomy terms.

Once I make a selection from the select field I would like to display the term image associated with with the selected term.

The values in the select field are the Term Name and not the ID or the slug...

Thanks for your help.

#1530957

There is no simple shortcode to get the term ID given the term name, and anyway you shouldn't set it up like this for multiple reasons. The simplest, most important reason is what I've already told you: the Types field shortcode for displaying a term image field requires a term ID. If you can't use the Types field shortcode, you'll have to write your own custom code to display a term field image, and you won't be able to use any of the image resizing or alignment attributes that are possible with a Types field shortcode.

Furthermore, It will be easier and more error-proof to find and display the name of a term with a known ID rather than going in the opposite direction to get the ID from the name. It is possible to have more than one term in a taxonomy with the same name, for example, but it is not possible to have more than one term in a taxonomy with the same ID. Furthermore, the ID of a term will not change but the name might.

So why do you want to use the term name as a value? We should probably work on solving whatever problem that creates instead. If the issue is you want to display the term names in the select field instead of IDs or slugs because the name is more legible, just use the term name as the option text and use the term ID as the option value:

<option value="123">Term Name</option>

Now you can get the selected option value and use it to display a Types term field image using the Types field shortcode.

What other problem can I help solve when using the selected term ID instead of the term name?

#1530993

Hi Christian,

Once again thank for the detailed response.

I see the issue. In my implementation of the select box I used custom code to dynamically populate the box option values from a specific Custom Taxonomy list.

The reason was to make that particular function 100% in sync with whatever the terms are in the meta list instead of having to manually duplicate the values in the option field everytime there was a change in name or an addition.

Incidentally, the termmeta image shortcode did retrieve the correct image using the slug alone so so far so good.

I think for now you have given me everything I need in the event my solution doesn't work you have provided details for an alternative so I thank you.

#1530995

My issue is resolved now. Thank you!