Support

Account

Home Forums Front-end Issues User Field Type Documentation Missing

Solved

User Field Type Documentation Missing

  • Hello,
    I can’t find Documentation anywhere on this website on the seemingly new ‘User Field’ type which shows under ‘Relationship’ in the plugin dashboard. When I write <?php the_field( ‘user-field-name’ ); ?>, it echoes many values of the selected user. I want to echo the Author URL for posts by this specific user. Kindly assist.

  • Hi @eugenenyawara

    I believe you can use the get_author_posts_url() function to get the URL of the author by using the user ID. To get the user ID from the user custom field, you can pass a false value to the third parameter of the get_field() function. It should be something like this:

    echo get_author_posts_url(get_field('user_custom_field', false, false));

    Where “user_custom_field” is the name of your custom field.

    I hope this helps 🙂

  • Thank you @acf-support Jimmy James! What I wish though, is if this information – “To get the user ID from the user custom field, you can pass a false value to the third parameter of the get_field()” could be public.

    If I had known how to get the ID from the field, I would have figured it. I am grateful for the help.

    To anyone else wondering, to get the User ID from the User Field,

    $userID = get_field('field-name', false, false);

  • Hi @eugenenyawara

    Yes, it’s documented on this page: https://www.advancedcustomfields.com/resources/get_field/. Maybe it’s not specific enough because it’s designed to be working with other field types too.

    Basically, ACF saves the ID of an object (post, page, user, taxonomy, etc.) in the database. If you set the format value (the third parameter) to false, it will get the raw entries in the database instead of parsing it to an object.

    I hope this makes sense 🙂

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

The topic ‘User Field Type Documentation Missing’ is closed to new replies.