Home › Forums › General Issues › How to set default custom field value on new posts for a specific user › Reply To: How to set default custom field value on new posts for a specific user
I’m afraid is not working.. wordpress is no longer loading!
Questions: where do I set the custom field name?
Oh and for the moment learning to create a plugin is beyond my learning scope right now..
I have so far:
function my_acf_prepare_field( $field ) {
$field['readonly'] = true; // optionally make the field read-only
if ( $field['Madrid'] ) { return $field; } // bail if field has a value already
$for_user = 2;
$current_user_id = (int)get_current_user_id();
if ( $current_user_id != $for_user ) { return $field; } // bail if not specified user
$ip = my_get_field_function();
if ( $ip ) {
$field['value'] = $ip;
}
return $field;
}
add_filter('acf/prepare_field/name=region', 'my_acf_prepare_field');
// this functions gets the custom field value
function my_get_field_function() {
if ( !empty( $field] ) ) {
$field_value = $field;
} else if ( !empty( 'Madrid' ) ) {
$field_value = 'Madrid';
} else {}
return $field_value;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.