Support

Account

Home Forums Add-ons Repeater Field dynamically generate subfield content Reply To: dynamically generate subfield content

  • Just in case anyone else needs this information.

    So, to create an arbitrary number of subfields for a new post, if I have a repeater named “bf_test_repeater”

    
    add_filter('acf/load_value/name=bf_test_repeater',  'afc_load_bf_test_repeater_value', 10, 3);
    function afc_load_bf_test_repeater_value($value, $post_id, $field) {
      if ($value === false) {
        // this is a new post since value === false
        // set value to number of default # of rows to create
        $value = 5;
      }
      return $value;
    } 
    

    I’ll have more code than this since it will need to figure out by looking at the options page how many rows to start with. Then I’ll need the code for each of the sub-fields to set the value to the next value retrieved from the options page.