Skip Navigation

[Resolved] Get custom field of taxonomy

This support ticket is created 5 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by federicoA 5 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1193008

Hi,
I have a custom type (course) with a taxonomy associated (staff=.
I created an archive file and retrieved all the values of the course with "types_render_field".
I do not understand how to recover the data of the associated taxonomy. I used get_terms ('staff') but I can not print custom fields (email, resume, ...).
Can you help me?
thank you

#1193039

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I would like to knwo here, are you using PHP template file where you want to display the associated terms attached to posts as well as custom fields belongs to those terms?

#1193057

yes I have created a single-course.php and I would like to customize it with the data entered in the back-office

#1193072

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - please refer to the following Doc that will help you how you can display the terms associated with post:
=> https://toolset.com/documentation/customizing-sites-using-php/creating-templates-single-custom-posts/#displaying-custom-taxonomy

To display the custom term field - you should use the Types API function: types_render_termmeta(). Please check the following Doc for related example:
=> https://toolset.com/documentation/user-guides/displaying-wordpress-term-fields/#displaying-term-fields-with-types-api

#1193226

I solved it like this (I do not know if I've done it correctly or there's a better method):

$staff_list = get_the_terms( $post->ID, 'staff');
foreach($staff_list as $st=>$st_id) {
$st_var = $st_id->to_array();
$st_term_meta = get_term_meta($st_var['term_id']);
echo $st_term_meta['email']:
}

#1193487

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can also use the following way:

$staff_list = get_the_terms( $post->ID, 'staff');
foreach($staff_list as $st=>$st_id) {
$st_var = $st_id->to_array();
echo types_render_termmeta("email",array("term_id" =>$st_var['term_id']));
}
#1214670

My issue is resolved now. Thank you!