0

I've make a custom field named "Phone" using buddypress xprofile plugin, but this field cannot be searched by Wordpress primitive searching engine, I found another field which is "user_url" this field is searchable.

The solution I'm looking for : (either one)

  1. Make "Phone" field searchable.
  2. hook "Phone" field's value to the "user_url" when user registering. Using "user_url" make the "phone" field's value become searchable.
  3. or setup a cronjob sync both fields hourly.

or others genius idea make it happen!

5
  • What is the reason for needing to sync the phone field to the user URL? Are users aware you're sharing personally identifiable data with Firebase? And are you sure that copying the value to the user_url field won't expose this information? In many European countries and some US states this would be considered a data breach
    – Tom J Nowell
    Commented May 31, 2021 at 20:12
  • @TomJNowell the reason for syncing the phone field to user URL is because the Wordpress user search function cannot search the external profile but the user URL field is searchable ,so that's why I'm trying to sync the field when user registering. For your concern , users is noticed for the use of their mobile number.
    – kengi
    Commented Jun 1, 2021 at 5:13
  • 1
    did you consider asking instead how to make the field searchable? You've fallen into the X Y Problem trap, instead ask how to solve your problem, not how to implement a proposed solution, and you'll get better answers
    – Tom J Nowell
    Commented Jun 1, 2021 at 8:24
  • @TomJNowell I think you're right, the best solution is make the external profile field searchable in frontend, but isn't it much more difficult to modify Wordpress primitive search? no idea about that. I have been stuck at this problem few days already, its drive me crazy.
    – kengi
    Commented Jun 1, 2021 at 9:26
  • The searchable columns of the user table are set by a filter developer.wordpress.org/reference/hooks/user_search_columns
    – Tom J Nowell
    Commented Jun 1, 2021 at 12:03

1 Answer 1

0

You do not need to, instead add the user URL column to the list of searchable table columns

https://developer.wordpress.org/reference/hooks/user_search_columns/

Which includes a user contributed example that does this:

https://developer.wordpress.org/reference/hooks/user_search_columns/#comment-4605

add_filter( 'user_search_columns', 'wpdocs_filter_function_name', 10, 3 );
     
function wpdocs_filter_function_name( $search_columns, $search, $wp_user_query ) {
    $search_columns[] = 'user_url';
    return $search_columns;
}

With this, no syncing to a URL field is necessary.

3
  • user_url is searchable by default ,thats why I want to sycn the phone field to user_url field and make the phone number become searchable :(
    – kengi
    Commented Jun 1, 2021 at 15:25
  • wait I think you've confused me, you can you please re-state your original problem clearly? I think based on this new comment that you actually want to search a custom field, and that user_url has nothing to do with your problem. This is really confusing, edit your question to ask about what you actually want to do and state it clearly and unambiguously. user_url is not a field, it's a table column, in a completely different table
    – Tom J Nowell
    Commented Jun 1, 2021 at 16:53
  • Sorry, updated the question. hope its clearly now.
    – kengi
    Commented Jun 1, 2021 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.