Support

Account

Home Forums Add-ons Options Page Select specific repeater rows from an options page Reply To: Select specific repeater rows from an options page

  • 
    // loading the field
    add_action('acf/load_field/name=select_field_name', 'load_select_field_name_choices');
    function load_select_field_name_choices($field) {
      $choices = array();
      if (have_rows('repeater_field_name', 'options')) {
        while (have_rows('repeater_field_name', 'options')) {
          the_row();
          $title = get_sub_field('services_title');
          $choices[$title] = $title;
        } // end while have rows
      }  // end if get field
    } // end function 
    
    
    // displaying the values
    $selections = get_field('select_field_name');
    // this is assuming that the select field returns an array of selected values
    if (!empty($selections)) {
      if (have_rows('repeater_field_name', 'options')) {
        while (have_rows('repeater_field_name', 'options')) {
          the_row();
          $title = get_sub_field('services_title');
          if (in_array($title, $selections)) {
            // get other sub fields from the repeater and display here
          } // end if selection is selected
        } // end while have rows
      }  // end if get field
    } // end if !empty