How to create more advanced WordPress user searches
In this article, we are going to see how to go beyond the default WordPress user search. We are going to see how to use some of the Users Insights features to create more advanced user searches.When running a WordPress site, we often need to find a specific user or group of users. Usually, what we’d do is to simply use the Users section of the WordPress dashboard. WordPress have a built-in search functionality which provides a way to search users by some parameters. But, as you might have noticed, the default user search functionality of WordPress is somehow limited. As a matter of fact, it only allows you to search users by a few different parameters like their username (nice name), name and their email. But what if you need to search users by different parameters like: user role, user profile data, custom field, post type or some other custom search term?
Users Insights extends the default WordPress user search functionality and provides a number of additional features and filters. This creates a better search tool that allows you to perform a lot more advanced and precise searches of your WordPress user list. There are many different filters and searches that you can perform with the help of the Users Insights smart filters, but in this article we are only going to focus on the ones that are related with the default WordPress user profile data like first name, last name, date registered, email, etc. If you want to learn more about the other ways you can search and filter your WordPress users with Users Insights, be sure to check the Features and Integrations sections of our website.
Searching WordPress users by their first and last name
When you are creating a new WordPress user you have the first and last name fields by default. They can be used in many ways by theme authors, and one of the most common ways is using them to identify comment authors.
But when using Users Insights you’ll be able to search through both First Name and Last Name fields separately or combined. So when you use a regular WordPress search form you don’t have the ability to specify where you are searching.
On the other hand, when using Users insights you can select if your search query will apply to first name, last name or event both. Let’s say you want to get all the Lee’s from your user base, you can do that by simply searching Lee as the display name.
But if you want to check just Lee as a last name, you can do that as well:
Now you can see that we’re using the “contains” filter. You have other options as well depending on how you want to filter out your users. Here are the different variations for your search criteria:
- Does not contain
- Is not
- Starts with
- Ends with
- Is set
- Is not set
You can see that each set of search criteria has its opposite. It just means that every time you are searching and get some results, searching for the opposite is going to hide all the current results, and show all users previously hidden.
Let’s have a look at each of these with some examples.
The contains filter is a broader view. It will return search results of all users that have this string, no matter where it appears in the selected field. For example, if we type “El” here are our results:
So we’ll get GabriEL, LouELla, EthEL and so on. The opposite (does not contain) will just reverse this logic, so any names that contain this string are going to be removed.
As for the “IS” filter, it’ll look for an exact match. Thus, if you know the user’s last name, for example, you can use it to filter them:
Should we search for a slight variation and we simply wouldn’t get this result. The “Is not” operator works in the same way, but removing the results that match our search text.
Regarding the “Starts with” and “Ends with” operators, they do exactly what it looks like. They’ll search our string in the beginning or end of our fields. Thus, if you want to export your users alphabetically, you can search for users whose name starts with “a”, then “b” and so on, exporting on each step:
The “is set” filter works in a little different way. Instead of allowing you to search for a specific name, it will show all the users who have any kind of value in the WordPress database set as their first name or last name fields in their WordPress profiles. The “is not set” field is particularly useful if you want to find all the WordPress users who have not entered their first name or last name on their WordPress profile page.
Searching WordPress users by email
The default WordPress user search functionality allows you to search your users by email. But this feature can’t be combined with other search methods and these can’t be exported. The Users Insights filters enable you to create more advanced WordPress user searches based on their email address.
If you click on the “Add Filter” button and select the email filter, you will notice that there are several different options that you can choose from. Similarly to the name search operators, each of them are going to be useful for certain scenarios.
The first option is the “contains” filter which, as the name suggests, allows you to perform a more broad search of your users’ email addresses.
There are many cases when this can be a useful filter to have. For example, if you want to find all the users that work in a specific company domain, but not limited to a country. So you could search for “@pepsi” and this is going to show you all users with emails from pepsi.com, pepsi.co.uk, pepsi.com.au, pepsi.com.br and so on.
Next, let’s see the “does not contain” filter. It works in a similar way, but it shows you search results that don’t contain the search phrase. This filter can be useful if you want to exclude a particular phrase or email domain from your user list, for example to exclude the free email providers such as hotmail, yahoo and so on.
In addition, the “is” and the “is not” filters will show you only users whose email address matches or doesn’t match that specific search term correspondingly. That’s useful when you know the user’s email (or just got an email from them) and want to know more about them.
As for the “starts with” and the “ends with” filters, in a similar way they allow you to perform searches of yours users by using the beginning and the end of their email address. The “starts with” filter can be used to gather all users with some common email names, such as admin, hello, contact, and so on:
Regarding the “ends with”, it could be used to get all emails from an exact domain, such as pepsi.com.
Searching WordPress users by role
The WordPress user page allows you to filter your users based on their role. Clicking on the role name at the top of the user list will show you all the users that have that specific role assigned. In a similar way, Users Insights also enables you to list all the users that have a specific role, just by using the “Role is” filter.
Users Insights however, also provides another role filter that you might find useful when when it comes to searching your WordPress users by their role. The “Role is not” filter allows you to show all the users who don’t have a specific role assigned. For example, if you want to see all the users that are not admins, you can just apply a filter “Role is not Admin”:
Searching WordPress users by username
The username filter of Users Insights works in a similar way as the name filters that we already discussed. This means that you can perform similar searches of your WordPress users by their username. For example, you can use the “contains” filter for more broad user searches and the “is” and “is not” for more specific searches. The filters “starts with” and “ends with” are also available.
Searching and sorting users by date registered
If you have ever been in need to find the most recently registered users in WordPress, you have probably noticed that there isn’t a way to do this with the default WordPress functionality. The user list in the WordPress dashboard is ordered alphabetically and there isn’t a Date Registered column in the user table. This information is only available in the user profile section and there isn’t a way to sort your users by date registered.
The Users Insights plugin makes the date registered field available in the Users Insights user table, as well as in the smart filters. Therefore, if you want to find your most recently registered users, all you need to do is click on the date registered column title. In this way the user list will get ordered by this field, showing you the most recently registered users at the top of your user list.
Since this information is also available in the filters, you can use it to apply custom filters based on the date the user has registered. Here is an example showing all the users that have registered in the last 30 days:
There are multiple filters that you can apply for the date registered field:
- Less than [number of days]
- More than [number of days]
- Exactly [on a date]
- After [date]
- On [date]
- Before [date]
WordPress users management is one of the most important things to do when you are planning to create a solid and reliable website using WordPress as a platform. In this article we have shown you how to manage your users with some advance features of the Users Insights WordPress plugin. We explored how using Users Insights as an internal search plugin can improve your user experience and improve your user search results. We saw the different internal search criteria you can use with the search plugin and when they can be useful for you. In case you are using custom user meta fields, make sure to check the How to display, search and filter WordPress user meta data, as well as check the other Users Insights integrations and features for more info.
We hope that this article was useful and that it will help you with the user management and organization on your WordPress website.