Support

Account

Home Forums Backend Issues (wp-admin) Page display only to user with specific acf

Helping

Page display only to user with specific acf

  • I think is a stupid question, but I’have not found a solution…
    I need to make a website, with some page visible only for registered user with specific value in field.
    For example, a page only for user with (acf) job: manager and location: germany.
    So each post need to have “a some sort of condition” of display….
    I already give some acf to the users.. the problem is about the display of the posts..
    Sorry for the english but i’m not native english speaker.

    Thx

  • It depends on what you want to not show. You would also have to have something on each page. For example a matching “country” field for location where “germany” would be stored.

    Then as an example, to not show the content of the page

    
    $page_country = get_field('location');
    $current_user_id = 0;
    if (is_user_logged_in()) {
      $current_user_id = get_current_user_id();
    }
    if (get_field('location', 'user_'.$current_user_id) == $page_country &&
        get_field('job', 'user_'.$current_user_id) == 'manager') {
      the_content();
    } else {
      echo 'permission denied';
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.