Home › Forums › Backend Issues (wp-admin) › Predefined field's value from a function or DB › Reply To: Predefined field's value from a function or DB
Hi @blexfort
You can define a text field via PHP and then set the ‘read_only’ field attribute to ‘true’. You can learn about this from the resource page here: https://www.advancedcustomfields.com/resources/register-fields-via-php/
You can then modify the value of this field by passing the slug via the acf/load_field filter like so:
<?php
function my_acf_load_field( $field ) {
//use some logic to get the new value
$field['value'] = $new_value;
return $field;
}
// all
// add_filter('acf/load_field', 'my_acf_load_field');
// type
//add_filter('acf/load_field/type=select', 'my_acf_load_field');
// name
add_filter('acf/load_field/name=field_name', 'my_acf_load_field');
// key
// add_filter('acf/load_field/key=field_508a263b40457', 'my_acf_load_field');
?>
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.