I am attempting to feed term meta values from my custom taxonomy, "firm"/"firms", on to a User profile page at author.php
.
Users are attached to this taxonomy thanks to the LH User Taxonomy plugin. I need to display term meta fields for the firm to which s/he belongs.
So far, I have managed to find wp_get_object_terms useful
. This code echos the slug and name meta of the taxonomy term; description also works...
$firm_terms = wp_get_object_terms( $curauth->ID, 'firm' );
if ( ! empty( $firm_terms ) ) {
if ( ! is_wp_error( $firm_terms ) ) {
foreach( $firm_terms as $term ) {
echo '<a href="' . get_term_link( $term->slug, 'firm' ) . '">' . esc_html( $term->name ) . '</a>';
}
}
}
It works, it seems.
However, I have only managed to output those three standard term meta fields - name, slug and description. In addition, I also have a couple of dozen other term meta fields thanks to putting an Advanced Custom Fields field group on the Edit User page, storing extra "firm" details. These are intended for output but they do not show, using code like this (fragment):
foreach( $firm_terms as $term ) {
echo $term->firm_social_twitter_handle;
}
Is wp_get_object_terms
only built to show name, slug and description? Is there a way I can also echo out fields like firm_social_twitter_handle and firm_geo_city?
Do I need to use a combination of that and get_terms
, or something else? I had earlier found some success using get_terms
, but couldn't manage to constrain it to only take meta from the taxonomy term to which the User is attached, like I can using the above wp_get_object_terms
code.