acf/prepare_field

Overview

This filter allows you to modify a field right before it is rendered onto the page. By this time, the field has been validated and it’s value loaded.

Changelog

  • Added in version 5.0.0

Parameters

  • $field – the field settings array. This can be modified and then returned

Usage

There are 4 ways to hook into this filter.

  1. acf/prepare_field – filter for every field
  2. acf/prepare_field/type={$field_type} – filter for a specific field based on it’s type
  3. acf/prepare_field/name={$field_name} – filter for a specific field based on it’s name
  4. acf/prepare_field/key={$field_key} – filter for a specific field based on it’s name

functions.php

<?php

function my_acf_prepare_field( $field ) {
	
	if( $field['value'] ) {
		
		$field['disabled'] = true;
		
	}

    return $field;
    
}


// all
// add_filter('acf/prepare_field', 'my_acf_prepare_field');

// type
// add_filter('acf/prepare_field/type=text', 'my_acf_prepare_field');

// name
add_filter('acf/prepare_field/name=my_text', 'my_acf_prepare_field');

// key
// add_filter('acf/prepare_field/key=field_508a263b40457', 'my_acf_prepare_field');

?>

Related