Support

Account

Home Forums Backend Issues (wp-admin) acf/load_field does not dynamically populate other custom fields

Solving

acf/load_field does not dynamically populate other custom fields

  • I am trying to populate select(multiple) fields with data from repeater fields in option page.

    //loadinam ekskursijas i selecta turo single
    function acf_load_excursions( $field ) {
      $field['choices'] = array();
      if( have_rows('excursions', 'options') ) {
        while( have_rows('excursions', 'options') ) {
          the_row();
          $value = get_sub_field('excursions_value');
          $label = get_sub_field('excursions_title');
          $field['choices'][ $value ] = $label;
        }
      }
      return $field;
    }
    add_filter('acf/load_field/name=excursions_opt', 'acf_load_excursions');
    
    //loadinam meals i selecta turo single
    function acf_load_meals( $field ) {
      $field['choices'] = array();
      if( have_rows('meals', 'options') ) {
        while( have_rows('meals', 'options') ) {
          the_row();
          $value = get_sub_field('meal_value');
          $label = get_sub_field('meal_title');
          $field['choices'][ $value ] = $label;
        }
      }
      return $field;
    }
    add_filter('acf/load_field/name=meals_opt', 'acf_load_meals');
    
    //loadinam transfers i selecta turo single
    function acf_load_transfers( $field ) {
      $field['choices'] = array();
      if( have_rows('transfers', 'options') ) {
        while( have_rows('transfers', 'options') ) {
          the_row();
          $value = get_sub_field('transfer_value');
          $label = get_sub_field('transfer_title');
          $field['choices'][ $value ] = $label;
        }
      }
      return $field;
    }
    add_filter('acf/load_field/name=transfers_opt', 'acf_load_transfers');

    When I am in post, trying to add/select items in select fields, it doesn’t populate with all repeater entries, first select field only gets last value of repeater, second select fields only get few and last select values seems to be populated correctly.

  • Ok, I have spotted the problem, it fails to show entries from repeater if it has the same value (repeaters consists of name(string) and value(number), in post im using multiple select field with Ajax. How can I solve this so I could have select options with same values and still see them in admin menu?

  • Are you still having a problem with this or did the last comment mean that you worked it out?

    If you’re still looking for help, are the select fields you’re trying to populate sub fields in a repeater?

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘acf/load_field does not dynamically populate other custom fields’ is closed to new replies.