Support

Account

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

  • When you create a subfield of a repeater it’s given the name and key just like the parent field is given. so you create the filter for that field name or key.

    http://www.advancedcustomfields.com/resources/filters/acfload_value/

    For example, when I do this my setup will have 3 filters, on for the repeater and 1 for each of the 2 sub-fields in that repeater. The first filter will set a number of default rows for the repeater based on the number of rows in options. The other two will set the values for each row. The only thing I left out of my description above is that I only want to set the value if the first filter actually set the number of rows. So my first function would actually look something like:

    
    add_filter('acf/load_value/name=my_repeater',  'afc_load_my_repeater_value', 10, 3);
    function afc_load_my_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
        // based on number of rows created on options page
        $value = 5;
        // add filters to call subfield filters here
        // they are only created if we're supposed to use the default values
        add_filter('acf/load_value/name=sub_field_1',  'afc_load_sub_field_1_value', 10);
        add_filter('acf/load_value/name=sub_field_2',  'afc_load_sub_field_2_value', 10);
      }
      return $value;
    }
    function afc_load_sub_field_1_value($value) {
      // get next value for subfield 1 and return
      return $value
    }
    afc_load_sub_field_2_value($value) {
      // get next value for subfield 2 and return
      return $value
    }
    

    the actual subfield filters would be a bit more complicated because the values from the options page would need to be stored in an array in a global variable so that it can be accessed by my function and then each function would need to step through the values to return the next value for each subfield.

    Like I said, I have not actually gotten to building the part where the subfields are set to the options page value. I just know what I’ll need to do when I get back to it and will test and figure out the details then.

    Sorry, that’s about the best I’m going to be able to do as far as an explanation right now.