Home Forums ACF PRO Cheate field visible but not editable


Cheate field visible but not editable

    • Jeant

    • July 21, 2020 at 4:00 am


    I want to create a field editable only by the admin on a real estate theme (Houzez on theme forest).

    The user should be able to submit a property trough front end, but on the same type of post, a field should be only editable by the admin, not the user.

    The field should be visible to the user, logged or not logged.

    Is this possible?

    If so, how?

    Im using ACF pro


    // replace with your field key
    // or adjust hook as described in above doc
    add_filter('acf/prepare_field/key=field_XYZ123', 'edit_admin_only');
    function edit_admin_only($field) {
      $readonly = true;
      if ((is_user_logged_in() && current_user_can('administrator')) ||
          (is_user_logged_id() && !$field['value'])) {
        // user is logged in  and is an admin
        // or user is logged in and the field has no value
        $readonly = false;
      $field['readonly'] = $readonly;
      return $field;
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.