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?
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
Thanks Waqar! BTW, is there a reason why I can't use numbers in the function names? I noticed that seems to break things.
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 )
My issue is resolved now. Thank you!