Skip Navigation

[Resolved] Dropdown with list of WordPress Subscribers

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

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/Hong_Kong (GMT+08:00)

This topic contains 12 replies, has 3 voices.

Last updated by Luo Yang 2 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2199297

Tell us what you are trying to do?
I want an editable field that can allows you to pick from the subscribers. I found a post listed below with a similar example but as usual, the details of actual implementation are sparse and I cannot get it to work.
1,
I used the code listed in the post in my functions.php file as directed.

But I'm not sure how to create the dropdown that uses the code in functions.php.
2.
in my post fields group, i added a dropdown field. then i added 'fillthecoachin4' into the field slug.

i get an empty dropdown ('not set'). how do i link a dropdown to get the data provided by the functions.php code?

Is there any documentation that you are following?
https://toolset.com/forums/topic/i-want-to-add-a-dropdown-with-a-list-of-all-members-with-a-certain-role/#post-328866

Is there a similar example that we can see?
https://toolset.com/forums/topic/i-want-to-add-a-dropdown-with-a-list-of-all-members-with-a-certain-role/#post-328866

What is the link to your site?
hidden link

#2199549

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Where do you intend to use this field?

In a front end form? On a back end post edit screen? Somewhere else?

#2199891

hi.
i want it to be a front end form. we have projects and here is an example project:
hidden link
i want to be able to add subscribers to this form. i also want it to be a repeating form.
so this is a film project. and i want to add subscribers to the form that will perform jobs such as director, director of photography, gaffer, etc.
so i want a repeating form that adds a subscriber and his job title.
thanks.

#2200469

Hello,

You can try filter hook "wpt_field_options" , for example:
1) Create a custom select field "My Select" with Toolset Types plugin
https://toolset.com/course-lesson/creating-custom-fields/

2) Add below codes into your theme file "functions.php":

add_filter( 'wpt_field_options', 'add_some_options', 10, 3);
//dynamically populate select field from Types
function add_some_options( $options, $title, $type ){
    switch( $title ){
        case 'My Select':
          
            $options = array(
				array('#value'=>'', '#title'=>'Choose user')
			);
            $speakers = get_users(array( 'role' => 'Subscriber' ));
          
            foreach ($speakers as $user) {
                $options[] = array(
                    '#value' => $user->ID,
                    '#title' => $user->user_login,
                );
            }
            break;
    }
    return $options;
}

It should be able to work in both admin side and frontend forms.

More help:
https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

#2200929
1 custom field added.jpg
2 added to both forms.jpg
3 edit backend of project.jpg

hi. see screenshots.
1.
i added the exact code you provided into the functions.php file.
2.
i created a custom field called "My Select".
3.
i added the field into the form for my projects (my custom post type)
4.
in the backend and frontend, the field is "not set".

#2201297

I have tried above custom codes in my localhost with a fresh WP installation + the latest version of Toolset plugins, it works fine.

Since it is a custom codes problem, if you need more assistance for it, please provide a test site with the same problem, fill below private message box with website credentials + FTP access, also point out the problem page URL and field group URL, I need a live website to test and debug

#2201891

Could you possible also make the "My Select" dropdown with subscribers have a link to that subscriber's profile? so on the front end, people will see the subscriber name and be able to click to go their profile page. thank you very much.

#2202283

Thanks for the details, I have done below modifications in your website:
1) Edit your theme file "functions.php", add the same codes I mentioned above:
https://toolset.com/forums/topic/dropdown-with-list-of-wordpress-subscribers/#post-2200469

2) Test it in frontend and admin side, it works fine, see the results here:
hidden link
hidden link

For the new question:

on the front end, people will see the subscriber name and be able to click to go their profile page. thank you very much.

I assume you are going to link to the user's archive page, I have modified the content template "Content template for Projects", in the bottom, add a shortcode block, with below codes:

My select: <a href="<em><u>hidden link</u></em> field='user_login' id='[wpv-post-field name="wpcf-my-select"]']/">[wpv-user id="[wpv-post-field name="wpcf-my-select"]"]</a>

You can see the result here:
hidden link

#2203077

That's great thank you!
Can you please explain why it works now and didn't work before?
The functions.php file you provided has not changed and the custom field has not changed. But now when I use the block "fields and text" on my project post (which inserts the shortcode [types field='my-select'][/types], it works now. Whereas it did not work until you went into the site. It used to say "Not Set".
Thanks.

#2203101

hi. it is showing only the user's first name and its linking to my account, not their account. i tried to play around with "display_name" vs "ID" in the functions.php code but that didn't solve the link issue so i put it back like it was. can you set it to display name and get the link to work? thank you.

#2204389

I have done below modifications in your website:
Edit the content template "Content template for Projects", change the shortcode block codes to:

My select: <a href="<em><u>hidden link</u></em> field='user_login' id='[wpv-post-field name="wpcf-my-select"]']/">[wpv-user field="display_name" id="[wpv-post-field name="wpcf-my-select"]"]</a>

Test it in frontend, it works fine:
hidden link

For the questions:
Can you please explain why it works now and didn't work before?

Since these are shortcodes, you need to use WP shortcode block to display them

#2206399

Hi. Thanks for working on this. I see now that I need to move this into a repeating field. I left your "My Select" field on the page (fo now) but added "Talent Name Select" select field into the repeating Group "Talent". When you go to the project page for example:
hidden link
I added a link called "Add new talent" to the "Add talent" section near the bottom of the page that takes you to a page to view and edit the repeating field group.
I duplicated the functions.php code you provided and changed the case statement to:
case 'Talent Name Select'

--
1.
the select field says "not set" as predicted. i would like to get this working.
2.
also, for some reason, the "My select" code you made has reverted from linking to the person's profile page again, and links to mine instead. we don't need that to work on the "my select" statement since we are moving to a repeating field but i wanted to point out the problem and hoped you can help me understand how to fix that issue so i don't have to contact support when this happens in the future.
thanks.

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/i-need-to-move-this-into-a-repeating-field/

#2206567

According to our support policy, we prefer one ticket one question.

I assume the original question of this thread is resolved, for other new questions, please check the new thread here:
https://toolset.com/forums/topic/i-need-to-move-this-into-a-repeating-field/

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.