Support

Account

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;