Dropdown field containing users on the system - display name instead of ID in a view

By: Mark Dix | Asked: 11/25/2022
ForumsCategory: Code SnippetsDropdown field containing users on the system - display name instead of ID in a view
Mark Dix asked 2 years ago

Hi Everyone 

I am hoping someone may have encountered this before or may be able to point me in the right direction. 

I have used the following code snippet: 

Add user dropdown: https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/#kb-add-user-dropdown 

The User from the dropdown is saved as the user ID when submitted and it all works fine. 

However, I would then like to use that field in a view but display the display_name and not the ID as it currently does as that is what is saved to the DB. 

$values['options'][] = array( 'label' => $user->display_name, 'value' => $user->ID );

I did try saving the value as the display_name but then one can not use the filter:

User ID - is equal to - current_user

Would anyone be able to suggest a way of doing this and any changes I need to make?

Many thanks  Mark 

1 Answers
Rob LeVineRob LeVine answered 2 years ago

If your view is showing the data for the logged in user, you can follow these directions, however, I'm guessing that's not what you're doing, so my suggestion is a making a custom shortcode that takes the id as a parameter and then uses the WP functions to get the information from user object. It'd only be a few lines of PHP.

Mark Dix replied 2 years ago

Hi Rob. Thank you very much for your answer. You are right it is not a User ID field unfortunately so those shortcodes will not work. Are there any support documents you know of that would get me started on creating a custom shortcode for what I would like?

Rob LeVineRob LeVine replied 2 years ago

It's your lucky Black Friday special day because I just wrote a tutorial a few days ago on this topic specifically.

https://connect.formidableforms.com/user-tutorials/custom-shortcode-creation-basic/

Mark Dix replied 2 years ago

Hi Rob

That is great thank you very much.

Thanks Mark

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right