Skip Navigation

[Resolved] Callback after select option

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Shane 5 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#1347405

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.

#1347409

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

toolset.PNG

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

#1347435

OK, so just a normal select .. be it.

How can I dynamically add values to a select, but have some disabled? is this possible?

#1347475

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

#1347521

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?

#1347577

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