Home Forums ACF PRO Creating a read only field


Creating a read only field

  • Hello,

    I’ve bought a developer license for ACF after using it on a few different sites. I’ve had a request from one of the customers I’m building a website for and they want the ability to have a read only field that’s populated whenever one of their users edits a post as a way of recording when it was last edited. We don’t want the users being able to go in and modify the date of this themselves but instead have the field populated with the current date.
    Does anyone have any ideas about how I can approach this?

    Thanks in advance

  • You can use the acf_save_post to update the field.

    The following function would disable the field on load.

    add_filter('acf/load_field/name=field_name', 'sampleFunction');
    function sampleFunction( $field ){ $field['disabled']='1'; return $field; }
  • Hi,

    I’ve just given it a go with a combination of another function to autopopulate it with today’s date but the field itself is still clickable. Is this supposed to happen or is the function you have given not worked?

    function my_acf_update_value( $value, $post_id, $field  )
        $time = date('d/m/Y');
    	$value = $time ;
        return $value;
    add_filter('acf/update_value/name=updated', 'my_acf_update_value', 10, 3);
    add_filter('acf/load_field/name=updated', 'sampleFunction');
    function sampleFunction( $field ){ $field['disabled']='1'; return $field; }
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.