Hi,
With Blocks, how may I add term fields to my term archive page ?
Thank you.
Hi, as far as I know taxonomy term fields aren't supported in either the single field block or the fields and text block, but I will double check with my 2nd tier support team. User and term fields and Views were not included in the first round of Blocks, so the best way to display these fields is to use the classic Types field termmeta shortcodes, for example:
[types termmeta="term-wysiwyg-field-slug"][/types]
You can place termmeta shortcodes in the archive output, either inside or outside of the archive loop.
Please stand by and I will let you know if my 2nd tier support team has some feedback on this.
Hello and thank you,
I've tried this within my Archive page applied on single terms :
<h1>[types termmeta="term-wysiwyg-field-name"][/types]</h1>
<h1>[types termmeta="term-field-name"][/types]</h1>
<h1>[types termmeta="term-name"][/types]</h1>
<h1>[types termmeta="name"][/types]</h1>
<br>
[wpv-filter-meta-html]
[wpv-layout-meta-html]
But none of the h1 shows up...
The code you shared here looks okay. This code is from a WordPress Archive, created in the Classic Editor, right? That should work:
<h1>[types termmeta="term-wysiwyg-field-name"][/types]</h1>
Assuming the slug of the term field is term-wysiwyg-field-name, the contents of this field should appear . If that is not the case, I will be glad to take a closer look. Can you provide login credentials?
<h1 class="">[wpv-taxonomy-title]</h1>
<p class="">[wpv-taxonomy-description]</p>
Those worked ok for title and description.
<p class="">[types termmeta="email-auteur"][/types]</p>
<p class="">[types termmeta="site-officiel-auteur"][/types]</p>
And those also for custom fields.
But now I need to get custom fields not managed by types but this doesn't work :
sur_spip : <a href="[types termmeta='old_url']">[types termmeta='old_id'][/types]</a>
Thank you.
I don't think there's an easy way to display non-Types custom term fields with any Toolset shortcode. You would need a custom shortcode that uses get_term_meta. Something like this recommended by Minesh: https://toolset.com/forums/topic/custom-shortcode-for-term-meta-data/#post-1116401
Thank you.
I've tried to adapt Minesh's code without success.
function func_get_term_meta_data($atts) {
global $post;
$term_ids = wp_get_object_terms( $post->ID, 'auteur', array( "fields" => "ids" ) );
if(is_array($term_ids)) {
// $locations = get_term_meta($term_ids[0]);
$locations=evo_get_term_meta('auteur', $term_ids[0]);
return $locations['old_id'];
}
}
add_shortcode( 'show_term_meta', 'func_get_term_meta_data' );
Should display the meta "old_id" of the term of the taxonomy "auteur".
But on this page I got this : hidden link
"Call to undefined function evo_get_term_meta()"
Thank you.
Yeah it needs a lot of adaptation. Here's a more complete example:
function archive_term_meta_func($atts) {
$a = shortcode_atts( array(
'slug' => ''
), $atts );
$term_id = isset(get_queried_object()->term_id) ? get_queried_object()->term_id : null;
if( $term_id && $a['slug'] ) {
return get_term_meta( $term_id, $a['slug'], true);
}
return;
}
add_shortcode("archive-term-meta", "archive_term_meta_func");
Then use it like this in an archive:
[archive-term-meta slug="some-slug"]
Amazing support, thank you very much !
My issue is resolved now. Thank you!