Is there a way to query the content of the ACF custom fields that I have created when I perform a user search in the WordPress Dashboard (i.e. perform a search on the “/wp-admin/users.php” page)? For example, if I have created an “eye_color” custom field for all of my users and type “brown” into my user search form field, is there a way to have WordPress return all users with a “brown” eye color in my search results?
Thanks for the question. This is something I have not yet documented, but WP has!
Just like the WP_Query class, there is a WP_User_Query class which you can use to search for uses based on args.
One of the args is for a custom field query. Here are some links to get you started:
Hope that helps.
Alright. That is helpful to know.
I had a follow up question but I think I just answered it for myself. Let me do some additional research and see if I can develop a working solution. I plan on returning to the forum to ask an additional question or to mark this issue as resolved.
The WP_User_Query class seems like a good way to search for users, but I currently do not see a way to make use of the class when an administrator searches for users in the Dashboard. If I were writing a separate search tool, the WP_User_Query class seems like it could work. But I want to tap into what WordPress already has in place.
Do you have any suggestions for how I can extend the functionality of WordPress’s existing user search tool?
A link to a pastebin of what I have in mind is below. (The code does not work as I expected it would.)
I think you are talking about using a WP filter to extend the columns on the user list wp-admin page? correct?
Thank you, again, for continuing to work with me on this issue.
I have read the threads at the URLs you posted. It seems the developers involved in the threads are trying to accomplish something different than what I am trying to do. I gather that they are trying to add a custom column to the users table in the Dashboard so that they can sort on the custom column. I, on the other hand, am trying to filter the entries in the table down to those who match the criteria I submit to the search form. I am thinking that sorting on a custom column will be a poor solution once the number of users gets large, i.e. 100, 500, 1000, 1000000. I want my administrators to only have to scan through the few user records that match their search criteria.
Did I misunderstand the solutions proposed in the threads at the URLs you posted?
Lastly, I should let you know that I have posted a more general question about this issue to the WP support forum. You can find my post at the URL below. My post has not yet received any replies.
Yes, that is correct. Specifically, I want my custom search filter to filter the users in the search results based on data that is in the
wp_usermeta table, in addition to the default behavior of filtering the results based on the data that is in the
I have searched on google and found a support thread which contains some code to add in a column and also modify the search args:
I also think you can use a plugin called ‘CodePress admin columns’.
Thank you for continuing to research this issue for me. Since the solution at the URL you provided seemed to demonstrate another way to sort the rows in the users table in the Dashboard, I developed a custom solution to meet my requirements. In short, I added an “Advanced Search” page to the “Users” section of the Dashboard and had the page call a MySQL procedure that I wrote. You can find more information about the solution I developed at the URL below to the WordPress support forum.
Thank you again for all of your help. Here is the URL.
The topic ‘Searching on Custom User Profile Fields’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Sorry for the issues with ACF's API SSL certificate this morning. We've resolved it and your activations and downloads should be back to normal again. Thanks! ^LG— Advanced Custom Fields (@wp_acf) November 2, 2022
© 2022 Advanced Custom Fields.