This developer-focused code recipe demonstrates how to query members with a specific custom field. The code can be adjusted to pull in active members with any custom user field you have in your membership site. 

Developers can then use the query result to build a custom lists like:

Query Active Members By User Meta Field Code Recipe Banner Image

About the Code Recipe

In the query example below, we show you how to query all active members that have a first_name, last_name, and pet_name in their profile. 

The code recipe returns an array of all users with their ID, email address, name, pet name, and membership information. 

The Code Recipe (PHP)

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

Developers with a working knowledge of MySQL can customize this recipe in loads of ways. You can adjust which user meta fields to query on, you can limit the result by a specific Level ID, and you can even adjust which user fields are returned by the query.

Alternatively, you can adjust this query to only return the user IDs for the result, then use the  general WordPress get_userdata function to return user information in the loop.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo