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

Question

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.';
}
?>

0
Pete 2 months 2023-09-26T22:54:41-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse