Home Forums Feature Requests Read-Only Field


Read-Only Field

  • i am late but you can also try something like this (with type):

    function disable_acf_load_field( $field ) {
    	$field['disabled'] = true;
    	return $field;
    add_filter('acf/load_field/type=text', 'disable_acf_load_field');

    or try to inspect $field array name with matches of your fields like:

    function disable_acf_load_field( $field ) {
    	$fields = "project_code","project_type","project_status","funding_year" // add more here
    	if(in_array($field["name"],$fields)) $field['disabled'] = true;
    	return $field;
    add_filter('acf/load_field/type=text', 'disable_acf_load_field');
  • Here is with new stylized True / False checkboxes. Tested and it works.

    add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field');
      function add_readonly_and_disabled_to_text_field($field) {
        acf_render_field_setting( $field, array(
          'label'      => __('Read Only?','acf'),
          'instructions'  => '',
          'type'      => 'true_false',
          'name'      => 'readonly',
    	  'ui'			=> 1,
    	  'class'	  => 'acf-field-object-true-false-ui'
        acf_render_field_setting( $field, array(
          'label'      => __('Disabled?','acf'),
          'instructions'  => '',
          'type'      => 'true_false',
          'name'      => 'disabled',
    	  'ui'			=> 1,
    	  'class'	  => 'acf-field-object-true-false-ui',
    • amjad

    • February 17, 2018 at 1:50 pm

    @hube2 Tried doing this for a radio button field. It did not work. Any suggestions?

  • Disabling and Setting fields to read only does not always work, depending on the field. I think you need to disable a standard radio field, bu I have not tried it in a while.

  • Perhaps not the most elegant way, but hey, it works!

    *    Prevents a field from being updated from the panel in ACF.
    *    Useful for business-critical fields that must only by updated internally, but still need to be visible on the admin panel.
    function prevents_field_from_being_updated_from_the_panel($value, $post_id, $field) {
            $backtraces = debug_backtrace();
            foreach ($backtraces as $backtrace) {
                if (!empty($backtrace['function']) && $backtrace['function'] == 'update_field') {
                    return $value;
            return get_field('field_5b5fcd08f9ecf', $post_id, false); # Change field_{key} to your field key/name
    # If you have the field Key:
    add_filter('acf/update_value/key=YOUR_FIELD_KEY', 'prevents_field_from_being_updated_from_the_panel', 10, 3);
    # If you prefer to use field name:
    # add_filter('acf/update_value/name=YOUR_FIELD_NAME', 'prevents_field_from_being_updated_from_the_panel', 10, 3);
  • Was this ever solved and put into core? Don’t want to be mucking around with functions.php for this functionality. What we need is not a ‘message’, but a Relationship field for example to only show as readonly. Thanks!

    • jsilver

    • November 8, 2019 at 6:44 am

    @pkhunter I wanted to created a read only “relationship” field that gets updated bidirectionally from a linked post. This is the solution I am using:

    // render readonly field on relationship settings
    add_action('acf/render_field_settings/type=relationship', function($field) {
      acf_render_field_setting( $field, array(
        'label'     => __('Read Only?','acf'),
        'instructions'  => '',
        'type'      => 'true_false',
        'name'      => 'readonly',
      'ui'		=> 1,
      'class'	=> 'acf-field-object-true-false-ui'
    // render relationships as links to the edit pages.
    add_filter('acf/prepare_field/type=relationship', function($field) {
      // check to see if this is a read only relationship field
      if (isset($field['readonly']) && $field['readonly']) {
        // the value is an array of post_ids
        $post_ids = $field['value'];
        // render them as a list
        echo "<ul style='margin-left:5px;'>";
        foreach($post_ids as $post_id) {
          $post = get_post($post_id);
          $edit_link = get_edit_post_link($post_id);
          echo "<li><a href='$edit_link'>" . $post->post_title . "</a></li>";
        echo "</ul>";
        // return false to stop default rendering
        return false;
      return $field;
    • skafte

    • November 29, 2019 at 3:39 am

    I would also like to add a big +1 to this as a basic feature request 🙂

  • Just want to reiterate a simple solution that got buried a bit earlier in the thread, which is to export your field group to PHP and incorporate that into your theme or plugin instead of using the GUI.

    Then you can just add disabled => 1 to any field array that supports it.

  • Some of us are using Oxygen Builder in case that matters for the best approach.

    In my use case I have an ID that I auto-generate and I don’t want anyone to change it – front end, backend – even an admin.

    How might I do that?


  • I’ve implemented the very helpful suggestion from @hube2 registering the read only settings to the settings field. Thanks!

    The only issue I have is that when creating posts programmatically the read only settings aren’t applied – this only happens after the first save in the admin screen.

    Is there a way I can force the setting to be applied when the post is created? Or can I manually trigger a save after post creation that would set them correctly?

  • @tomgreeen The suggestion I made should work, it has nothing to do with the content saved in the field. But then that was done years ago.

  • Cheers. You’re right, it was something else in my implementation causing the issue. It still works nicely. Thanks !

Viewing 15 posts - 26 through 40 (of 40 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.