Title: echo user field in loop
Last modified: October 1, 2017

---

# echo user field in loop

 *  [burnleydesign](https://wordpress.org/support/users/burnleydesign/)
 * (@burnleydesign)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-user-field-in-loop/)
 * I’ve created a user field called ‘location’ and added it to my authors.php file
   using the following shortcode:
 * `<?php echo do_shortcode("[types usermeta='location' user_is_author='true'][/
   types]"); ?>`
 * Works great!
 * I also have a page called page-template-authors.php, where I’m listing all my
   authors, but I can’t figure out how to get the shortcode to work within this 
   page. Obviously, using the current author isn’t an option, because the loop is
   running through all authors. Instead, I need to tap into the existing loop. I’m
   using Elegant Theme’s Extra theme. As an example this is the code calling the
   display name of the author:
 *     ```
       <?php foreach ( $authors_page_vars['authors'] as $author ) { ?> 
       <?php echo esc_html( $author->display_name ); ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Anonymous User 14808221
 * (@anonymized-14808221)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-user-field-in-loop/#post-9550920)
 * You need to get the Object of the user in the Loop.
    As you see, the Theme does
   that in a foreach.
 * And then, it outputs the information from each user.
    You could also get the 
   ID and since our ShortCode supports the ID attribute, you can pass the User ID
   as a variable in the ShortCode.
 * But, in PHP it is better to display this data with the API:
    [https://wp-types.com/documentation/customizing-sites-using-php/functions/](https://wp-types.com/documentation/customizing-sites-using-php/functions/)

Viewing 1 replies (of 1 total)

The topic ‘echo user field in loop’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/types_ced1d3.svg)
 * [Toolset Types - Custom Post Types, Custom Fields and Taxonomies](https://wordpress.org/plugins/types/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/types/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/types/)
 * [Active Topics](https://wordpress.org/support/plugin/types/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/types/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/types/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: Anonymous User 14808221
 * Last activity: [8 years, 8 months ago](https://wordpress.org/support/topic/echo-user-field-in-loop/#post-9550920)
 * Status: not resolved