Support

Account

Home Forums Bug Reports ACF Pro – Options pages with Repeaters not working Reply To: ACF Pro – Options pages with Repeaters not working

  • If you’re trying to circumvent needing WP to load completely then you might want to take look at accessing the repeater field directly using get_option() instead of get_field(). To be 100% honest, I almost never use get_field() or most of the other functions built into ACF, basically because I want everything to work should ACF be deactivated for some reason…. of course if this is more than simple fields, like images or wysiwyg editors then it can be a lot more work. Here’s an example.

    
    // the options name used by ACF to store the repeater
    $repeater = 'options_'.$your_repeater_field_name;
    // array of sub field names
    $subfields = array(
      'field_1' => 'text',
      'field_2' => 'image',
      'field_3 => 'wysywig'
    );
    // place to put the repeater values
    $values = array();
    $count = intval(get_option($repeater, 0));
    for ($i=0; $i<$count, $i++) {
      $value[] = array();
      foreach ($subfields as $subfield => $type) {
        $value[$subfield] = get_option($repeater.'_'.$i.'_'.$subfield, '');
        switch($type) {
          case 'image':
            $value[$subfield] = wp_get_attachment_image_src(intval($value[$subfield]), 'full');
            break;
          case 'wysiwyg':
            $value[$subfield] = apply_filters('the_content', $value[$subfield]);
            break;
          case 'text';
          default:
            // do nothing;
        }
      } // end foreach $subfield
      $values[] = $value;
    } // end for $i