How to Search Your BuddyPress Members by Location

Have you ever wanted to be able to search and filter your BuddyPress members by their location? In the following article, I’m going to show you how to search your BuddyPress members by their location right from your WordPress dashboard, with the help of the Users Insights plugin and its Geolocation module.

 

Getting Started

To get started you first have to make sure that you have installed and activated the Users Insights plugin on your BuddyPress website. Also, for this tutorial, we are going to need the BuddyPress and Geolocation modules of Users Insights activated. You can activate them from the Module Options section of the Users Insights plugin in your WordPress dashboard.

The Geolocation module, when activated, will automatically detect and store your BuddyPress member location every time they visit your website. This module detects and stores the following information: the city, region, and country where the member is located. The Geolocation module also adds a few filters into the Filters section of Users Insights that allows you to search and filter your members by using the members’ location data. This data is also available in the BuddyPress reports page.

 

Sorting the BuddyPress member list by location

The geolocation data that the Users Insights plugin detects and stores for your members will be then available in the Users Insights table. The table columns that contain this information are the City, Region, and Country. You can show/hide these fields from the user table by clicking on the “eye” icon. If you want to order your member list by the country they come from, you can do this by simply clicking on the title of the column “Country”. This will sort your buddypress members list in a ascending order by the name of the country.

buddypress search members by location

If you click once more, the list of users will be sorted in a descending order.

 

Showing only members from a specific country

If you want to show a list off all the members from a specific country you can add a filter  “Country is” or “Country contains” and type the name of the country. Here is an example of the list of all the members from the UK.

buddypress search members by location

By using the operator “is not” you can easily list all the members that are not from a specific country. Since the Users Insights filters are stackable, you can use multiple filters at once. For example, filters that show a list of all the members that are not from UK and Australia.

buddypress search members by location

Using BuddyPress custom fields location data

If you have a BuddyPress custom profile field where your members can set their location, thanks to the BuddyPress module of Users Insights, you can use this information to filter your members. When you activate the BuddyPress module of Users Insights you automatically get all the custom fields created with the xProfile fields feature of BuddyPress, available in the user table and the smart filters. So if, for example, you already have a custom field for “Country” that your members complete, you will be able to filter your members by the data that they have set into this custom field.

Using multiple filters

As we have already mentioned, Users Insights allows you to use multiple filters at once. This gives you the ability to segment your BuddyPress members by using multiple properties. The possibilities are endless, but let’s see some interesting examples. Let’s say that you want to find all the members that are from France and are active members of your community. You can do this by adding one filter “Country is France” and a second one “Last Seen is less than 60 days ago”.

buddypress search members by location and activity

But how about if we have some other requirements, like the member needs to be male and younger than a certain age. Considering that you actually have this information about your customers (from their custom profile fields), we can easily do this by adding a third filter “Gender is Male” and finally, another filter that is going to show us only the members that were born after 1 January 1984.

See your BuddyPress member locations on the map

Besides the Users Insights user table, the member locations can be also displayed on an interactive map. You can access the map view by clicking on the globe icon above the user table. This map shows all of the detected by Users Insights member locations. Moreover, all of the Users Insights filters are available in the map view, so you can easily filter the members by different criteria and yet preview the segmented list of member locations on the map.

buddypress member location map

Additionally, the location of each member is displayed on a smaller map in the User Profile section – you can access this page just by clicking on any user from the Users Insights list. This section also lists the country, region and city, as well as the rest of the member related data that Users Insights detects, such as BuddyPress custom fields data, activity, groups info, etc.

buddypress geolocation in profile

Going deeper with geolocation filtering for BuddyPress

Further to the basic location searches, you can find out your entire BuddyPress member map, by combining the filtering and map functions. Let’s see some examples of how you can do that.

We also mentioned that you have not just the country, but also city and region filters when using the GeoLocation API. Therefore, you can create a BuddyPress map by filtering and platting users from specific locations.

The first BuddyPress map we’re going to create is showing all users from a specific country. First, you can just filter users from that country:

Users from the US

Then, you can use the map feature to see these users on your map.

Map view of US users

As you can see, in the map view users who are close to each other are going to be grouped. But it’s very easy to zoom in and out and figure out which users are from which location.

Users zommed in view

You can also create different maps for each information you need from your users. For instance, you may want to find all Italian-speaking users in New York City using this filter. Then you just switch to the map view:

Italian-speaking users from US

The BuddyPress member map is going to give you a new look at your customer base. For example, you may find certain neighbourhoods where you have the most active users. This can give you invaluable information about these users, and how to find more users similar to them.

Table view of your most active users

Check out the difference between the table and the map view of this same search:

Map view of the most active users

The map view shows you trends regarding user location, how they are spread, and how appealing your site is for different audiences.

Here is a short video showing you how to use the geolocation feature to search and filter your BuddyPress members:

In this video you can also see how to easily add and remove filters, and how they can be used in combination with other data.

That’s it! Now you know how to search your BuddyPress members by their location. We hope that you find this article useful and that it will help you to better manage and organize your BuddyPress community.