Home Forums General Issues Populate select field with post title


Populate select field with post title

  • I found some results on this forum on how to populate select ACF select fields from another ACF field, is there a way to populate the select field with a custom post type title?

  • I think I solved my own issue, the below seems to work, if anyone sees a flaw here please let me know, otherwise I hope this helps anyone with the similar issue.

    function acf_load_author( $field ) {
    	$field['choices'] = array();
    	$the_query = new WP_Query( 'post_type=profiles' );
    		while ($the_query -> have_posts()) : $the_query -> the_post();
    		$value = get_the_title();
    		$label = get_the_title();
    		$field['choices'][ $value ] = $label;
    	return $field;
    add_filter('acf/load_field/name=author_select', 'acf_load_author');
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Populate select field with post title’ is closed to new replies.