Home Forums General Issues User Field – User ID


User Field – User ID

  • First of all stellar job on the ACF plugin…long time user of it and I just see it getting better all the time.

    I’m building a website at the moment where a user will be able to access the content if their user ID matches the one selected in the wp backend using ACF. One problem I’m having is that the User field pumps the user meta out as an array and I only need to ID. Is there an easy way to grab that info?

    Any help is massively appreciated!

    <?php $client_id = get_current_user_id(); if ($client_id == get_field('user_select')) { ?>
    <p>user private info</p>
    <?php } ?>
  • Hi @higgypop

    Easiest solution is to store the value in an array and compare like so:

    $client_id = get_current_user_id();
    $selected_user = get_field('user_select');
    if ($client_id == $selected_user['ID'] ) { ?>
    <p>user private info</p>
    <?php } ?>
  • Awww man that worked spot on. Legend. Cheers mate.

  • Hey Elliot. Thanks again for the great answer…If I can pick your brain one final time. If I wanted to use the multi select field type rather than single select how would that affect the above code?

    Thanks in advance!

  • Hi @higgypop

    If you select a multi-select, the value from get_field will be an array containing multiple user arrays.

    You will need to loop through the first array and check then match the sub array ID

    Some simple var_dump debugging will help explain how the data is structured


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

The topic ‘User Field – User ID’ is closed to new replies.