I am trying to show term fields in my woocommerce products archive. I am using different taxonomies for my products: Spielort (Location), Bundesland (Country). These taxonomies have custom fields like a description, an image and the address of the location.
I am using these in my taxonomy archive loop and it works fine:
<h4>[wpv-post-taxonomy type="spielort"]</h4>
<p>[types termmeta='strasse-spielort'][/types]<br>
[types termmeta='plz-spielort'][/types] [types termmeta='ort-spielort'][/types]
</p>
Now I need a way to also show them in my product archive loop. When I am using this code, it just shows nothing. Your documentation (https://toolset.com/documentation/user-guides/displaying-wordpress-term-fields/) says "At the moment, you can display term fields on a View listing terms and on a term archive page.".
I really need some way to show the termmeta on different pages. Can you show me a workaround to do this? There has to be some way to get them via PHP, but I can't figure it out.
Thanks in advance.
Kind regards
Theo
Hi, the same document you linked to contains some information about how to display these terms using PHP. For example, let's say 'strasse-spielort' is the slug for a textfield. You could use this code to output the strasse-spielort field:
types_render_termmeta( "strasse-spielort", array() );
The second parameter, array(), can include any attributes you want to pass into the Types API. The available attributes for each type of field are defined in the API documentation here:
https://toolset.com/documentation/customizing-sites-using-php/functions/
You can also see some PHP examples for each field type (click the + More orange link).
If you want to be able to display these values in your Content Templates or Views, where you can't use raw PHP, you can create custom shortcodes that call these PHP functions for you. Here's a very simple implementation of that concept:
add_shortcode( 'display_termmeta_field_info', 'display_termmeta_field_info_func');
function display_termmeta_field_info_func($atts)
{
$slug = $atts['slug'];
return types_render_termmeta( $slug , array() );
}
In your Content Template or Page or Post, etc:
[display_termmeta_field_info slug="strasse-spielort"]
More information about creating your own custom shortcodes can be found here:
https://codex.wordpress.org/Shortcode_API
If there is a specific step in the process you're having trouble with, feel free to reach out here and I can try to assist. Let me know how far you can get, and where you are stuck.
Dear Christian,
thank you very much. This was very helpful. But now I am getting to a different problem:
I am using the taxonomy "Spielort" (Location) to give my products (event tickets) a location structure. For example:
Saarland -> Baker Street Criminal Tearoom & English pub
Saarland -> Hotel xyz
Saarland -> and so on ...
Rheinland-Pfalz -> Hotel abc
Rheinland-Pfalz -> and so on ...
...
This archive template will list all products in 'saarland' or in a specific location like 'Baker Street'. The product list also contains the address, which comes from the attached 'spielort' (location) in the product loop. The address also comes from the custom term fields in 'spielort' 2nd level ('Baker Street').
I just realize, it is hard to explain, without showing. Could you please set my next response to private, so I could provide you some credentials to show you what it should look like. Enclosed you will find a screenshot.
Thanks in advance
Kind regards
Theo
Hi, I'll be glad to take a look at that - may I kindly ask you to open a separate forum ticket? Since this is a separate issue, I would prefer to address it independently. This keeps our forum organized so it's easier for other users to search for answers to their problems.
Feel free to assign the ticket directly to me and I will begin as soon as I can. Thank you!
How I can ein create a new ticket and assign it to you?
First, you mark this ticket as resolved. Then, when you create a new ticket, the system will offer you the option to assign that ticket directly to the supporter who worked on your most recent ticket. There aren't many tickets in the queue right now, so if you have trouble assigning to me, just create the ticket and I will assign it to myself. I'll watch the queue for a ticket from your profile.