Support

Account

Home Forums General Issues Searching on Custom User Profile Fields

Solved

Searching on Custom User Profile Fields

  • 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?

  • Hi @pursuit

    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:
    http://codex.wordpress.org/Class_Reference/WP_User_Query
    http://stackoverflow.com/questions/12392847/wordpress-user-query-order-by-meta-value

    Hope that helps.

    Thanks
    E

  • 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.

  • Hi @elliot,

    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.)

    http://pastebin.com/LuFeG1jg

  • Hi @pursuit

    I think you are talking about using a WP filter to extend the columns on the user list wp-admin page? correct?

    If so, please checkout these docs:
    http://pippinsplugins.com/add-user-id-column-to-the-wordpress-users-table/
    http://wordpress.org/support/topic/make-extra-columns-in-userphp-sortable

    Thanks
    E

  • Hi @elliot,

    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.

    http://wordpress.org/support/topic/querying-the-wp_usermeta-table?replies=1

    Thank you.

  • Hi @pursuit

    Just to clarify, you want to use the wp-admin user page but add a custom search filter to query the data?

    Please let me know if this is what you are attempting to do. It seems I don’t quite understand your question yet.

    Thanks
    E

  • Hi @elliot,

    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 wp_users table.

  • Hi @pursuit

    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:
    http://wordpress.org/support/topic/make-extra-columns-in-userphp-sortable?replies=17

    I also think you can use a plugin called ‘CodePress admin columns’.

    Thanks
    E

  • Hi @elliot,

    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.

    http://wordpress.org/support/topic/querying-the-wp_usermeta-table?replies=2

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Searching on Custom User Profile Fields’ is closed to new replies.