Advanced Custom Fields ACF dynamically set default value #wordpress
<?php | |
add_filter('acf/load_field/name=field_name', function($field) { | |
global $post; | |
// variant 1 (use get_post_meta instead of get_field to avoid conflicts) | |
if( get_post_meta($post->ID, 'field_name', true) == '' ) { | |
$field['value'] = 'FOO'; | |
} | |
// variant 2 | |
$field['default_value'] = 'FOO'; | |
return $field; | |
}); |
This comment has been minimized.
This comment has been minimized.
Hello Brad, thanks for your feedback. |
This comment has been minimized.
This comment has been minimized.
Hi thanks for the snippet. Got a question - I've created sth like that but seems not to work:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Thanks for this. I might be wrong but variant 1 works and variant 2 doesn't.