Populate ACF repeater with current structure of pages

by joelybristol   Last Updated January 14, 2018 11:08 AM

I'm hoping someone can put me in the right direction of how I can achieve this. I know that ACF repeaters can be populated with default values like so.

function my_acf_load_value($value, $post_id, $field) {
if ($value !== NULL) {
// if the value is exactly NULL it means
// the field has never been updated
// we don't want to change fields that have already been editied
return $value;
// set the new field value
$value = array(
// add a nested array for each row
  // add an array item for each sub field
  'field_name_1' => 'Value for Field 1',
  'field_name_2' => 'Value for Field 2'
  return $value;

What I wan't to achieve is get all pages by the current user and input these into sub fields AND sub-sub fields matching the site structure and hierarchy of pages (taking on board parents and grandparents etc)

So for example if the page structure we're like this:

Page 1
- Page 2
 - Page 3
 - Page 4
 - Page 5
Page 6
- Page 7
 - Page 8
 - Page 9
 - Page 10

I'm hoping to work with the acf_load_value function, any starting points or tips of how I can achieve this would be great.

Related Questions

Check ACF fields in foreach custom taxonomy

Updated April 23, 2015 22:03 PM

Query between dates using ACF Date Picker fields

Updated April 26, 2016 08:03 AM