Support

Account

Home Forums General Issues How to display taxonomy term custom meta?

Helping

How to display taxonomy term custom meta?

  • 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>slug, 'firm' ) . '">' . esc_html( $term->name ) . '</a>';
                    }
            }
          }

    It works, it seems (although I’m suspicious about the merit of foreach here – each User will only belong to one “firm”).

    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 custom term meta fields (ACF) like firm_social_twitter_handle and firm_geo_city?

    Do I need to use a combination of that and get_terms, or something else, like ACF output code?

    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.

  • I am running ACF Pro 5.5.14, so I assume ACF should now be saving to term meta (?).

    I participated in a previous thread in which it was said this would be supported from 5.5.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to display taxonomy term custom meta?’ is closed to new replies.