Skip Navigation

[Resolved] Set custom Toolset select field with user ID and displayname from specific role

This support ticket is created 4 years, 1 month 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)

This topic contains 2 replies, has 2 voices.

Last updated by tineB 4 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#2240713

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!

#2240727

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

#2241329

My issue is resolved now. Thank you!