1. Tell us what you are trying to do?
- I'm trying to set values from all users (user ID and displayname) with role Sponsor in a custom Toolset select field named kind-sponsor.
Is there any documentation that you are following?
https://toolset.com/forums/topic/custom-select-field-with-dynamic-data/
Is there a similar example that we can see?
I've created this script, but it does not propagate the kind-sponsor field:
<?php
add_filter( 'wpt_field_options', 'generate_sponsor_values', 10, 3);
function generate_sponsor_values( $options, $title, $type ){
switch( $title ){
case 'kind-sponsor':
$options = array();
$args = array('role' => 'Sponsor');
// Queries all the users with sponsor role
$user_query = new WP_User_Query( $args );
if ( ! empty( $user_query->get_results() ) ) {
$options[] = array('#value' => '',
'#title' => '--Selecteer sponsor---',
);
foreach ($user_query->get_results() as $user) {
$options[] = array(
'#value' => $user->ID,
'#title' => $user->display_name,
);
}
} else {
echo $options[] = array(
'#title' => 'No users found');
}
break;
}
console.log($options);
return $options;
}
What is the link to your site?
hidden link
Hope you are able to help me out!
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
Thank you for getting in touch.
In order for this to work you will need to use the field's title and not the slug. Please change kind-sponsor to the actual title, i'm assuming its Kind Sponsor.
Thanks,
Shane
My issue is resolved now. Thank you!