Please can someone provide a suggestion on how to populate a list field column with all the post id’s and post titles from a single custom post type (‘publisher’).
When transforming a list column into a select field, the gform_column_input filter requires each choice to be an array. The format should be:
array( “value” => “1”, “text” => “HarperCollins” ),
array( “value” => “2”, “text” => “Penguin Random House” ),
array( “value” => “3”, “text” => “Macmillan” )
The function I am using to create a key/value array to represent each publisher is:
function choice_option_arrays() {
$output = "";
$query = new WP_Query( array( 'post_type' => 'publisher' ) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) : $query->the_post();
$output .= 'array( "value" => "' . get_the_id() . '", "text" => "' . get_the_title() . '" ),';
endwhile;
wp_reset_postdata();
}
return rtrim( $output, ',' );
}
I am then using the result of this function in my gform_column_input filter as shown:
function create_select_field_column( $input_info, $field, $column, $value, $form_id ) {
return array(
'type' => 'select',
'choices' => array(
choice_option_arrays()
)
);
}
add_filter( 'gform_column_input_1_1_2', 'create_select_field_column', 10, 5 );
How do I get my gform_column_input filter to recognize the output of my choice_option_arrays() function as a series of arrays, rather than as a literal string?
Any suggestions very much appreciated.
Thank you.