• Resolved parakeet

    (@parakeet)


    Having installed this, attached a taxonomy to Users and begun ticking the values on User profiles…

    How would I output the term meta on a User’s author.php profile page?

    In my scenario, taxonomy is “firms”, and, since ‘single_value’ is defined ‘true’, a User can only be associated with a single “firm”.

    Term meta for “firms” is various details about that firm, eg. firm_geo_city. My goal is, on author.php, to output the details of the “firm” to which s/he belongs.

    I presume I should use get_term_meta, but I’m not sure how.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author shawfactor

    (@shawfactor)

    best to use wp_get_object_terms:

    https://codex.wordpress.org/Function_Reference/wp_get_object_terms

    and edit author.php and add something like this:

    <?php $user_terms = wp_get_object_terms( user->ID, ‘firms’ );
    if ( ! empty( $user_terms ) ) {
    if ( ! is_wp_error( $user_terms ) ) {
    echo ‘

    ‘;
    }
    }

    ?>

    Plugin Author shawfactor

    (@shawfactor)

    sorry the forum manged my code but you get the drift, use the user-.ID as the object and the user taxonomy as the taxonomy then loop through the results

    Plugin Author shawfactor

    (@shawfactor)

    Then obviously use get term meta within the loop to get the meta data foir each term (including geo in your example)

    Thread Starter parakeet

    (@parakeet)

    Thank-you, Peter – and for the plugin generally.

    I went with…

    $firm_terms = wp_get_object_terms( $curauth->ID, 'firm' );

    Then, for name, slug or description…

      if ( ! empty( $firm_terms ) ) {
          if ( ! is_wp_error( $firm_terms ) ) {
                  foreach( $firm_terms as $term ) {
                      <strong>echo $term->slug</strong>;
                  }
          }
      }

    but, for other meta…

      if ( ! empty( $firm_terms ) ) {
          if ( ! is_wp_error( $firm_terms ) ) {
                  foreach( $firm_terms as $term ) {
                      echo <strong>get_term_meta( $term->term_id, 'firm_site_url', true )</strong>;
                  }
          }
      }

    The difference I hadn’t realised was – you call those three standard taxonomy metas (name, slug, description) directly with $term->name, but you call extra added meta using get_term_meta.

    • This reply was modified 6 years, 9 months ago by parakeet.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to output on author.php’ is closed to new replies.