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.
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/
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?
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/