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

  • I’m building a plugin, so I’m building everything into a PHP class. I say this because you need to create some counters to keep track of where you are. If you’re not using classes then you’ll need to use global variables to do the counters.

    Here are the steps.

    During initialization I read in the values from the repeaters and store them into an array. The array will need to be either a class property or global variable. this function should probably run at “plugins_loaded” to make sure that ACF functions are available for retrieving your repeater field data.

    the next step is to set the correct number of repeats. That’s done with the function I gave in my last comment. You just need to return the count of the array that holds your subfield data.

    For each subfield you need to create a another filter, along with a counter to keep track of where you need to be.

    global $subfield_1_counter;
    $subfield_1_counter = 0;
    add_filter('acf/load_value/name=subfield_1',  'afc_load_dubfield_1_value', 10, 3);
    function afc_load_dubfield_1_value($value, $post_id, $field) {
      global $subfield_1_counter;
      // code to calculate next value for this field
      // the exact code here will depend on the type of field being initialized
      // after setting the value, increment the counter and return the value
      return $value;

    To be honest, I don’t have exact details on what I did because I haven’t completed this part yet. Like I said, I’m doing this for a plugin that I’m building and my attention has been diverted from that project. This is how I plan to proceed when my workload drops enough so I can return to it.

    Hope this helps.