Tell us what you are trying to do?
Using a toolset select I would like to get a callback after an option has been picked.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Nelson,
Thank you for getting in touch.
Actually we don't have a callback function for this.
Take a look at the screenshot. These are the only functions we have for the filters.
Thanks,
Shane
OK, so just a normal select .. be it.
How can I dynamically add values to a select, but have some disabled? is this possible?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Nelson,
This hook will only work on the backend.
However this is not a public hook so it is an undocumented hook so support on it is limited.
This one below was built to get values from another CPT.
add_filter( 'wpt_field_options', 'populate_select', 10, 3);
function populate_select( $options, $title, $type ){
switch( $title ){
case 'Team leader':
$options = array();
$args = array(
'post_type' => 'team-leader',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'wpcf-active',
'value' => 'Yes',
'compare' => '=',
),
),
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$first_name = get_post_meta($post->ID,'wpcf-first_name');
$last_name = get_post_meta($post->ID,'wpcf-tmsurname');
$options[] = array(
'#value' => $post->ID,
'#title' => $first_name[0]." ".$last_name[0],
);
}
break;
}
return $options;
}
Replace "Team Leader" with the name of your select field. Then you need to modify the args array to fit your CPT that you want to get the value from.
Then within the foreach you need to populate the options array with the correct values.
Please let me know if this helps.
Thanks,
Shane
The problem there is i can't pass extra arguments for the select. I can see a value-title pair. Can I pass extra options? Such as disabled or optgroup. Any way I can do that?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Nelson,
Unfortunately no you're not able to do this through php.
However you should be able to using jQuery to target a select option by its value.
Thanks,
Shane