Support

Account

Home Forums General Issues Conditionally display textarea contents only to those users chosen from Us

Helping

Conditionally display textarea contents only to those users chosen from Us

  • How to conditionally display an ACF custom textarea contents only to those users chosen from an ACF User field.

    I have an ACF User field (allowed_users)that author’s can multiple select when they create a post. I also have an ACF textarea field (private) in the author’s post (author’s only have 1 post). I’m trying to conditionally display the textarea on the front end only for those users the author selected. This is what I have…

    
    <?php
    $allowed_users = get_field('allowed_users');
    $custom_field_value = get_field('private');
    $current_user_id = get_current_user_id();
    if (in_array($current_user_id, $allowed_users)) {
        echo $custom_field_value;
    } else {
        echo 'You do not have permission to view this content.';
    }
    ?>
    
  • What is the return value set to for the user field?

    You either have to set it to return “User ID” or you have to get the unformatted value

    
    $allowed_users = get_field('allowed_users', false, false);
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.