Home Forums Add-ons Repeater Field Populate select field with values from repeater field Reply To: Populate select field with values from repeater field

  • Hi @davidjustin

    This will be possible, but lets first forget about the AJAX side. Lets make it a bit more basic:

    1. The user selects a post type
    2. The user saves the post
    3. The user sees the select field populated with repeater values from the post type selected

    function my_acf_load_field( $field )
    	// globals
    	global $post;
    	// load selected value from post type field
    	$p = get_field( 'Field_B', $post->ID );
    	// now load repeater field from selected post object
    	if(get_field( 'Field_B', $p->ID ))
    		// loop through the repeater and use the sub fields "value" and "label"
    		while(has_sub_field('Field_B', $p->ID))
    			$value = get_sub_field('value');
    			$label = get_sub_field('label');
    			$field['choices'][ $value ] = $label;
        return $field;
    // acf/load_field/name={$field_name} - filter for a specific field based on it's name
    add_filter('acf/load_field/name=Field_A', 'my_acf_load_field');

    This is untested but should work. After you have it working, you can write some AJAX to fetch the values.