Skip Navigation

[Resolved] In a parametric search filter, replace a number by the author having this ID

This support ticket is created 7 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#557782

Hello,
I have set a parametric filter in a view that lists numbers, where each number is the ID of an user.
I need now to replace displaying of those numbers by the "display_name" value of each user.
Is it possible to do this in PHP ? Or must I use JS here ?
Thank you.

#557918

Let me make sure I understand your question. This is a custom field filter, and this custom field contains values that represent User IDs. You are using this custom field to link Posts and Users somehow, and in your search filter you would like to show the User display name instead of the numeric ID that is saved in the custom field. Is that correct?

The only way I can think of to do this is to remove the custom field filter from your Filter Control editor area, and insert a custom filter with PHP. Somehow you must get all the possible custom field values as an array of numbers. Then you must loop over each value to construct HTML options in a custom select field, or HTML checkboxes. Use the WordPress get_userdata() method to determine the display name of each user, and set the labels and values of each option to use the name and ID:
https://codex.wordpress.org/Function_Reference/get_userdata

Then you can use the Views API hook wpv_filter_start_filter_form to insert your custom filter in a View's filter controls automatically:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_start_filter_form

Once you have the inputs in your filter area, you can begin using your custom filter controls to update the search results.

#559151

Thank you for your complete answer.
Please don't close this thread yet ; I need a little bit more time.
Thank you.

#559336

No problem, I will mark this thread as pending an update from you. The ticket will remain open for 30 days. No need to reply right now.