Support

Account

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

  • I did something like this to populate a select field.
    
    add_filter('acf/load_field/key=field_59969e19e1e31', 'my_acf_load_field');
    function my_acf_load_field( $field ){
        $field['choices'] = array();
        $field['choices'][''] = '';
        $titles = array();
    	$args = array(
            'post_type' => array('some_post_type'),
            'post_status' => 'publish',
            'posts_per_page' => -1,
            'orderby' => 'title',
            'order' => 'ASC',
        );        
        $clients = get_posts( $args );
    	foreach ( $clients as $client ) {
    		$choices[] = $client->ID;
            $titles[] = $client->post_title;
    	}
        if( is_array($choices) ){
    		foreach (array_combine($choices, $titles) as $choice => $title) {
                $field['choices'][ $choice ] = $title;
            }
    	}
        return $field;
    }