Skip Navigation

[Resolved] How to display custom term fields in the front end.

This support ticket is created 2 years, 8 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.17 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 2 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#2130333

I created a taxonomy (Type of therapy) for one of the Toolset custom post and added Custom Fields Group (Term Fields) to it. It contains only an Image field because I want each type of therapy has an associated logo or with it. Its working. Now I want to show the type of therapy and its logo one of the content template. The single field block give option of showing custom taxonomy but it give no option of showing the logo associated with it? Please help me in this.

#2130411

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting Toolset support.

Currently, the blocks editor does not support term fields and user fields yet. You will need to use shortcodes. However, even with shortcodes, you can't access term fields from a post context only with shortcodes. You will need to use a taxonomy view.
Please check this article and let me know if you have any questions about it https://toolset.com/documentation/user-guides/views/displaying-wordpress-term-fields/

#2135443

Actually I don't want to have all my custom taxonomy on a single page (ie. in a view) with their Term Fields. I have a view of all the therapists and every therapist has a speciality( it's taxonomy) and on the content template a therapist I want to show its
speciality along with its term field. How can this be done?

#2137371

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Well, there are only two ways of displaying term fields:
- Using a taxonomy view, which is only available with the legacy editor. Check this screenshot hidden link
- Using a custom shortcode. For example, the following shortcode will display the term field with the slug "field-slug" for the taxonomy with the slug "tax-slug":

/**
 * Display term field from the current post
 */
function my_post_term_field_fn( $atts ){
  
    global $post;
	
	// Attributes
	$atts = shortcode_atts(
		array(
			'field'     => '',
			'tax-slug'  => '',
		),
		$atts
	);
	
	if ( !$atts['field'] || !$atts['tax-slug'] ) {
		return '';
	}
  
    // Get ID of taxonomy term assigned to the post
    $term_ids = wp_get_post_terms( $post->ID, $atts['tax-slug'], array( 'fields' => 'ids' ) );
	
	if ( !count( $term_ids ) ){
		return '';
	}
  
    // Output the term field
    return types_render_termmeta( $atts['field'], array( 'term_id' => $term_ids[0] ) );
}
add_shortcode( 'post-term-field', 'my_post_term_field_fn' );

And use the shortcode like:

// Use like so by passing required attributes
// [post-term-field field="field-slug" tax-slug="tax-slug"]

Check this article on how to add custom code:
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

You may be interested in this article too, about creating custom shortcodes:
https://toolset.com/documentation/programmer-reference/adding-custom-code/how-to-create-a-custom-shortcode/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.