Hello, I have created a pre-populated field with the code below:
add_filter( 'wpt_field_options', 'populate_select_1_1', 10, 3);
function populate_select_1_1( $options, $title, $type ){
// Custom List of Speakers
switch( $title ){
case 'Presentation Speaker':
$options = array();
$args = array(
'post_type' => 'mdsc-speakers',
'posts_per_page' => -1,
'post_status' => 'publish',
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}
Is it possible to have a blank default option at the top of the select list so that I can check to see if the field is set? For example, in the attached screenshot, I would like it to start with "Select Speakers" so that I can check to see if the field value is "true" or not.
A side question: is it possible to remove "Enter your internal title for the item" for repeatable groups?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
To add a default option using the wpt_field_options hook, you can add it by adding the code:
$options[] = array(
'#value' => 0,
'#title' => "Please Select",
);
For example:
- Please try to use the following code and check if that helps you to resolve your issue.
add_filter( 'wpt_field_options', 'populate_select_1_1', 10, 3);
function populate_select_1_1( $options, $title, $type ){
// Custom List of Speakers
switch( $title ){
case 'Presentation Speaker':
$options = array();
$args = array(
'post_type' => 'mdsc-speakers',
'posts_per_page' => -1,
'post_status' => 'publish',
);
$posts_array = get_posts( $args );
$options[] = array(
'#value' => 0,
'#title' => "Please Select",
);
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}
I have split the ticket for your additional question:
"Enter your internal title for the item" for repeatable group
I will handle it with the following ticket:
=> https://toolset.com/forums/topic/split-blank-default-option-in-pre-populated-select-field-how-to-change-reove-enter-your-internal-title-for-the-item-for-repeatable-group-field/