• 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)

    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/

Viewing 1 replies (of 1 total)
  • The topic ‘echo user field in loop’ is closed to new replies.