Home Forums ACF PRO Displaying users (relationship field) results in "array" in post


Displaying users (relationship field) results in "array" in post

  • Hello.

    For our website where we have articles which have multiple authors writing a piece we would want to use ACF to credit the other authors.

    To do this we have created a new field called coauteurs (both label and field named like this)
    field type set to user, allowed it to be empty, multiple options to be selected and set the output displayed as “user array” (the others being user object and user id).

    So far so good, when we are in the article we get a drop down list where we can select the users.

    However when we try to display them on the page all we get are the words “Array”,
    one of the options we have tried is this one:

     									* coauteurs
                    echo get_field('coauteurs');

    Any ideas how we can get the author names to be displayed here ?

  • Hello Nessler,

    The user field allows you to choose three options to return data.

    1. User Array
    2. User Object
    3. User ID

    With the first being the default. You have a few options here to get the data you want.

    Since this is an array, you can do a little digging and use something like this in your template to find the exact fields you want to display:

    <?php var_dump( get_field('coauteurs') ); ?>

    Then once you pick the fields you want, you can do something like this:

    // Get the user
    $user_data = get_field('coauteurs');
    echo $user_dzata['display_name'];

    Hope this helps.


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

The topic ‘Displaying users (relationship field) results in "array" in post’ is closed to new replies.