Skip Navigation

[Resolved] Being able to search by user map field

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a custom search View so my site visitors can search for other site Users using an address field and possibly a distance filter.

Solution: There is no way to directly search for Users using a custom search View. The best approach here is to create a proxy post type for Users, as described in the documentation below. Then create your search View to find those proxy posts, which are directly related to their corresponding Users (post author).

Relevant Documentation:
https://toolset.com/documentation/user-guides/how-to-create-custom-searches-and-relationships-for-users/

This support ticket is created 5 years, 10 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 4 replies, has 2 voices.

Last updated by Line49 Design 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1192733

Tell us what you are trying to do? I have created a custom map field for users. I want to be able to display all users of a particular role on a map, which I currently have working. But now I want to all the public to be able to search for users in a particular location. What I would really like to have is a province dropdown that would show only users in a particular province when a province is selected. The province would need to come from the user's map field.

I tried adding this in the Search & Pagination section:
[wpv-filter-controls][types usermeta='user-map-address'][/types][/wpv-filter-controls]
but it didn't add a Query filter. If I manually add the Map address field as a query filter, I don't know how to set it up so the public can enter content into the field and it narrow the selected users.

When I setup a new Search View and change the Content Selection to Users, then I get the following message: Only Views listing posts can have custom search inputs.

I tried using this: [wpv-geolocation][wpv-view name="find-an-officiant"] [/wpv-geolocation] but that didn't seem to work either, it asked to use my location, but didn't change the map.

Is there any documentation that you are following? I found documentation on how to setup searches for posts, but not for users content types

Is there a similar example that we can see? I would really like it to function like this page: hidden link but using user data instead of posts. Distance from the public persons location would be awesome, but if that is not possible, then being able to type in a province or city or address and the map field is used to find users that match.

What is the link to your site? hidden link

#1192761

Hi, there is currently no direct way to set up parametric searches for Users in Views. Instead, the best approach is to create a proxy custom post type that stores User data, something like "Members". Each User will be the author of one corresponding Member post. You can store address information in the Member post, instead of the User. Then perform your parametric search based on Member posts, not Users. We have some information about this approach available here: https://toolset.com/documentation/user-guides/how-to-create-custom-searches-and-relationships-for-users/

Let me know if you have additional questions about that.

#1193279

Hi,
Is there any way to create the User Custom Post Type record in the backend?

On our site, we create the user record manually, so we would also need to create the user custom post type record manually. But when I create a new user custom post type in the backend, I can only choose non-subscriber type users for the Author field. We have a new role setup for the members that we create, but they can't be allowed to edit the site.

We are using Ultimate Member to create the member profile. Is there anyway to show Ultimate Member fields in the View that displays the User Custom Post types?

Thank you.

#1193331

Is there any way to create the User Custom Post Type record in the backend?
Yes, you can add some custom code that allows all User roles to be selected as the author of the post:

function wpdocs_add_members_to_dropdown( $query_args, $r ) {
  // Unset the 'who' as this defaults to the 'author' role
  unset( $query_args['who'] );
  return $query_args;
}
add_filter( 'wp_dropdown_users_args', 'wpdocs_add_members_to_dropdown', 10, 2 );

We are using Ultimate Member to create the member profile. Is there anyway to show Ultimate Member fields in the View that displays the User Custom Post types?
I don't really know how that plugin works. Are their fields associated directly with the User account (usermeta table), or is there a separate custom post type that is used to store that information (postmeta table)?

#1195616

My issue is resolved now. Thank you!