Can't overwrite value attributes in select fields
-
I am using caldera_forms_render_get_field to create a filter that adds custom options to a select field (‘which_order’).
Basically, I’m trying to loop through a custom WP_Query object and display an option in the select field for each post.
This is partially working — I am successfully outputting the post titles in the dropdown. However I can’t seem to overwrite the “value” attribute for each option. Here is my code:
add_filter( 'caldera_forms_render_get_field', function( $field ) { if ( 'which_order' == $field['slug'] ) { $args = array( 'post_type' => 'time-card', 'post_author' => get_current_user_ID(), 'post_status' => 'order-complete' ); $orders = new WP_Query($args); if ( $orders->have_posts() ) : while ( $orders->have_posts() ) : $orders->the_post(); $name = get_the_title(); $id = get_the_ID(); $field['config']['option'][] = array( 'value' => $id, 'label' => $name, ); endwhile; wp_reset_postdata(); endif; } return $field; });My question is simply this: Why does ‘label’ => $name work, but ‘value’ => $id does not?
The topic ‘Can't overwrite value attributes in select fields’ is closed to new replies.