Support » Plugin: Advanced Custom Fields (ACF) » [Plugin: Advanced Custom Fields] Allow PHP in field 'Default Value'

Viewing 3 replies - 1 through 3 (of 3 total)
  • Did you ever find a way to do this?

    Thread Starter Kenneth Jensen

    (@kennethj)

    No, sadly not.

    You could use a filter of ACF via your theme functions.php, something like this:

    A field named my_field, insert name at name= in add_filter() line.

    A default value of php_default_hack for that field.

    function my_acf_load_value( $value, $post_id, $field ) {
    	if ( $value == 'php_default_hack' ) {
    		// do your php magic here...
    		$value = 'this is set from php';
    	}
    	return $value;
    }
    add_filter( 'acf/load_value/name=my_field', 'my_acf_load_value', 10, 3 );

    The code does this: If your field has the value php_default_hack during load, the value will be replaced by this is set from php.

    See also http://www.advancedcustomfields.com/resources/filters/acfload_value/

    For your example, note that a new created post has no slug = post_name yet.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Advanced Custom Fields] Allow PHP in field 'Default Value'’ is closed to new replies.