Home Forums General Issues Field type user output


Field type user output

  • Hi I am using a custom field with Field Type as user. However the output displays all the information for that user when selected. ID, Name, Nickname, Bio etc. Is it possible to limit it so it only outputs the Users Name?

  • Hi @lsbwebdesign

    ACF does not have any filter that would allow you to hack into this.

    Hmm… Have you tried writing a custom function that would filter out the values for you. The custom function would look something like this:

    function get_user_field($field_name, $post_id, $format=false) {
    $user_field = get_field($field_name, $post_id, $format);
    return $user_field['user_nicename'];

    Now when getting the user field, you would get is like this $username = get_user_field('user_field_name', 22);

    Hope this helps 🙂

  • Thanks for the reply. I have been trying to tweak the code to work but I just can’t seem to get it right. The field I am trying to use is also in an ACF options page so I think I have to change it a bit:

    I don’t suppose you have any experience with that do you?

  • Hi @lsbwebdesign

    Well, it is pretty simple.

    If the field is on an options page, You have to pass 'option' for the post_id parameter as explained in the docs. This should work:

    $username = get_user_field('user_field_name', 'option');

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

The topic ‘Field type user output’ is closed to new replies.