Skip Navigation

[Resolved] wpt-field-option function not loading select field

This support ticket is created 4 years, 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by larryL 4 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#1771565

I added an additional function :

add_filter( 'wpt_field_options', 'add_more_options', 10, 3);
function add_more_options( $options, $title, $type )
{
    switch( $title )
    {
    case 'replacement officer':
        $args = array(
            'orderby' => 'display_name',
            'fields' => array( 'ID', 'display_name')
        );
        foreach( get_users($args) as $user ) {
            $options[] = array(
                '#value' => $user->ID,
                '#title' => $user->display_name,
            );
        }
        break;
    }
    return $options;
} 
     

to pull in the users in a form that already has another field 'user-id' that also does the same thing (that one is working). But this one does not work.

The post form already has the select field jquery in place

jQuery(document).ready(function() {
    jQuery('select[name="wpcf-replacement-officer"]').toolset_select2();
});

is there a conflict that doesn't allow me to do this?

#1772061

Hi,

Thank you for contacting us and I'd be happy to assist.

I see two reasons why this code is not working:

1. Out of 13 custom field groups on the website, I found a field "replacement officer" in the field group "Absence Tracking".

The title of this field is "Replacement Officer" and you should also be using the same in the code.
( instead of "replacement officer" )


case 'Replacement Officer':

2. The "wpt_field_options" filter works for the select type fields, where some options can be involved.

The field that you currently have is just a "single line" type field, which is why no options can be added to it.

Please remove this field and add it again with the same title, but the field type should be "select".

regards,
Waqar

#1773855

Thanks Waqar! BTW, is there a reason why I can't use numbers in the function names? I noticed that seems to break things.

#1775823

Thanks for writing back and your observation is correct.

In PHP, user-defined function names can only start with with a letter or an underscore.
( ref: hidden link )

#1776619

My issue is resolved now. Thank you!