Support

Account

Home Forums ACF PRO get user tyle field separately

Solving

get user tyle field separately

  • I’ve added a “user” type field called “student”, and got it’s content in front page with <?php the_field(‘student’); ?>
    I get all user information together (name, lastname, id, username, image, etc).

    I would need to get only “username” separately in order to use it as variable.

    My goal is use the username to prevent other user access the page information.
    Something like:

    if ($current_user->user_login == ‘USER_NAME_ACF_FIELD’) {

    Thanks

  • I’m looking for similar info – I’d like authors to be able to select a user (so I used filed type “User”), and then I want to display the selected user’s name, and email address, and leave the rest of the array out. Something like this (if I was after the info from author, but I want to get this from selected user):
    <?php
    $author_id = get_the_author_meta( ‘first_name’);
    echo $author_id;
    $author_email = get_the_author_meta( ‘user_email’ );
    echo $author_email;
    ?>

    Any word?

  • I’m having the same issue. For some reason the field returned is not acting like a true Array. If I do echo get_field(‘user_name’) I get all of the values separated by a comma. If I do echo count($user_field) it shows 11 values.

    However, when I try to pull out an array value I can’t get it to work. I’ve tried a bunch of stuff. I’m totally stuck and I can’t find any documentation on ACF about it.

  • Done! Thanks to the ACF support for this.
    This is the way:

    <?php
    $user = get_field(‘YOUR_FIELD’);
    echo $user[‘user_nicename’]; // displays nicename of user
    ?>

    The user field returns an array which contains the following information:

    + KEY ++ DESCRIPTION +

    ID User ID
    user_firstname First Name
    user_lastname Last Name
    nickname Nick name
    user_nicename Nice name
    display_name .Display Name
    user_email Email Address
    user_url Web Address
    user_registered Date Registered
    user_description Description

  • thank you! it works for me. 🙂 i seem to be having success also using [‘user_avatar’].

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

The topic ‘get user tyle field separately’ is closed to new replies.