How to filter BuddyPress members by custom profile fields
Custom fields give you the ability to collect and display custom user data. BuddyPress provides the options to create your custom user fields via the extended profile feature. Once created, the custom fields can be easily added to your member profile page. From here, your members can add, remove or update their information if they wish so. Additionally, you have the option to make some of these fields required in the registration process. This gives you the ability to not only collect additional information from your members, but also make this information automatically available in the member profile page.
The BuddyPress module of Users Insights retrieves all the data from the custom profile fields and makes it available in the Users Insights user table. All the custom fields are also available in the smart filters, so you can search and filter your members by your BuddyPress custom fields data right from your WordPress dashboard.
Adding BuddyPress Custom User Fields
The BuddyPress extended profile feature is by default only available to the administrators. In order to be able to use this feature, you need to be logged in as administrator or have the permissions to create custom fields. You can access the custom fields feature via the “Profile Fields” link under the “Users” menu of your WordPress dashboard.
Let’s say, for example, that you want to know the occupation of your BuddyPress members. For this, we will need to create a new custom field “Job Title”. You can do this from the “Add New Field” section. When creating (or editing) a custom field, we also have the option to choose whether this field is going to be required or not. Another thing that we have to decide when creating a custom field is the type of the field.
BuddyPress provides several different field types that we can choose from, depending on the type of information that the field is going to store. If for example, the custom field is a “Birthday” field, then we can select the Date Selector field type. For cases when the field is going to store one of a predefined set of values, we can use the Drop Down select field type. For our example, we are going to choose the “Text Box” option, since this is the most appropriate type for this field.
We can also set the visibility of the field so we can establish who will be able to see the field in the member profile. We have the option to limit the visibility of the field to only the member’s friends or just to the member himself. Once we have set our field preferences, we can go and save the field settings. This field should now be available under the user profile section. Please note that you might not be able to see the field if there isn’t any data saved for it. You can add data to the field via the edit profile section of BuddyPress.
Using Users Insights to filter the members by the BuddyPress custom profile fields data
All the custom user data that you collect might not be of much use if you are not able to analyze it and get valuable insights from it. Users Insights provides advanced tools that can make the process of understanding your member data a lot more efficient.
The BuddyPress module of Users Insights will automatically detect all the custom profile fields that are added via the xProfile section. These fields are automatically added to the Users Insights user table and filters. This means that you can now filter and search your BuddyPress members based on the custom profile data that they have added via their profile. The BuddyPress custom fields are also displayed in the Users Insights custom profile section.
Now that we have created a custom field for our members’ occupation, we can search and filter our members by their job title. To do this, all we have to do is to add a “Job Title contains” filter and type the occupation that we are looking for.
Since the “Job Title” field is a text field type, we have the option to type a custom search term in order to filter the members by this field.
If we have a custom field that has predefined limited options for the members to choose from, Users Insights will automatically detect this field as an “Option field” and make the options available in the filter. Here is an example of filtering the user list by the “Freelance Availability” field. This field is registered as a “drop-down field”, where the users can choose between a few different options, such as “full-time available” or “not available”.
If the custom field is a date field, Users Insights will automatically recognize this and provide the corresponding date operators in the filter. Additionally, Users Insights also provides a date picker interface for easier and more convenient data input. Here is an example of applying a filter to list the members that were born after a specific date:
For more information about all the different field types that the Users Insights plugin detects, you can refer to the Custom Fields section of the BuddyPress module page.
Advanced BuddyPress profile search
In addition to the basic search functions, you can also use Users Insights to perform more advanced BuddyPress searches. It’s possible to combine the different data types and custom fields to gather more information about your users.
For instance, you may want to perform a BuddyPress profile search by users depending on their language in addition to their occupation. This is going to give you a more narrowed down view of your users. In order to perform this BuddyPress search just use these filters:
Since the languages is a text field, you can perform partial searches, and the regular is/is not searches. So, for instance, you may search for BuddyPress members who do not have English as one of their languages.
Let’s see more BuddyPress profile searches examples. The language is a text-based field, but you can perform equally powerful searches with number-based fields. For example, you can narrow down which users are in a certain age group and are available for freelance work. This can be done because the number fields allow comparison filters (greater than, smaller than).
The date-type fields allow BuddyPress searches very similar to the number-based fields. They allow comparisons using a fixed date as a reference, or using the current date. Thus, you can perform searches such as “X days ago”, or “after X date”. For instance, if you want to search all female users who were born after 01/01/1980, you can use these filters:
And finally, there are the system-generated fields. These are often number fields and they allow you to perform BuddyPress profile searches based on your user activity. For instance, if you want to find which are your most active users, with more than 10 friends you can use these filters:
Here is a short video showing you how you can use the Users Insights filters to search and filter your BuddyPress members by their custom profile data: