• Resolved jana90

    (@jana90)


    Hi all,

    I am coding my own theme with the help of already developed html/css/js pages from webflow (I exported the code and am now converting the pages)

    One thing I can’t figure is out, is how to display user information on the front end. For example, on my post template, I have a sidebar and have some html code there to display the author image, name and author bio. Here is the plain html code:

    <div class="sidebar-div">
        <div class="author-details-div">
    
          <div class="author-image" style="background-image:url('<?php echo get_field( 'field name' ); ?>');"></div>
    
          <div class="author-text-div">
            <h2 class="heading"> Author Name</h2>
            <p class="paragraph-2">Author Bio</p>
          </div>
        </div>

    When googling on how to display the author name (as an example), I found these two options:

    <?php echo get_the_author(); ?> and
    <?php get_the_author_meta( 'display_name', $author_id ); ?>

    So I tried placing these code snippets in the h2 tag, like this:

    <h2 class="heading"> <?php get_the_author_meta( 'display_name', $author_id ); ?></h2>

    But it’s not working, nothing will be displayed on the front end.

    I also added an acf image field to display on the backend for each user to set their profile pic. I want to display this acf image field on the front end with the other author details (see html code from above). The acf field is being displayed on the backend and I can set the image when editing user’s profiles, but when adding the php code to display the image on front end, it again won’t show.

    However, if I change the acf field’s location in the backend, to be displayed on the post’s page (instead of the user profile page), then with the same php code, the image will be displayed.

    So I guess there is something additional I have to do to display information that sits in the user profile in the backend? Can anyone help?

    • This topic was modified 3 years, 11 months ago by jana90.
    • This topic was modified 3 years, 11 months ago by jana90.
    • This topic was modified 3 years, 11 months ago by bcworkz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • $author_id

    Can you check if that has a value? Usually, you get the user like this:

    <?php $user = get_user_by( 'id', $user_ID ); ?>

    Moderator bcworkz

    (@bcworkz)

    If your code is within a post loop, you don’t need the $author_id parameter at all, WP will get the ID from the post’s author property. Outside of a loop but on an author’s archive page, you can get the requested author ID with get_queried_object_id().

    After you resolve the ID issue, you also need an echo statement.
    echo 'Posted by: ', get_the_author_meta('display_name');

    Generally speaking, any WP “get_the_*” function will require echo if you want the returned value output.

    Thread Starter jana90

    (@jana90)

    Hi all! Thank you for answering! I did a stupid mistake and that’s why the meta data from the user wasn’t displayed … I didn’t added the post loop. Now that I did that, the following code worked for me to get the user name and bio:

    <h2 class=”heading”><?php echo get_the_author_meta( ‘first_name’, false ) ?></h2>

    For the ACF Image Field that I set to be placed for users, I needed the following code to make it being displayed on the front end as well:

    <?php $author_id = get_the_author_meta(‘ID’); ?>
    <div class=”author-image” style=”background-image:url(‘<?php the_field(‘image2’, ‘user_’. $author_id ); ?>’);”></div>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to display User Information on the front end?’ is closed to new replies.