Home › Forums › General Issues › How can I set the default value of a field dynamically? › Reply To: How can I set the default value of a field dynamically?
function my_acf_load_field($value, $post_id, $field) {
if (empty($value)) {
$value = get_the_title($post_id);
}
return $value;
}
add_filter('acf/load_value/name=character_overview_title', 'my_acf_load_field', 20, 3);
if you field has never been set then this will not work, in this case you must put it in the code where you want do show it.
$text = get_field('character_overview_title');
if (emtpy($text)) {
$text = get_the_title();
}
echo $text;
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.