Passer la navigation

[Résolu] Set custom Toolset select field with user ID and displayname from specific role

This support ticket is created Il y a 4 years, 6 months. 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 -

Fuseau horaire du supporter : America/Jamaica (GMT-05:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par tineB Il y a 4 years, 6 months.

Assisté par: Shane.

Auteur
Publications
#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?
lien caché

Hope you are able to help me out!

#2240727

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: 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!