This code recipe demonstrates how to allow users to filter results shown by the Member Directory and Profile Pages Add On by adding a widget to the member directory’s sidebar. This feature allows users to search through your member directory more effectively while also improving their experience on your site.

Banner Image for Allow Users to Filter Results in Member Directory Post

About the Code Recipe

The Member Directory and Profile Pages Add On provides a shortcode to display your site’s members and information about those members in a variety of different layouts. This functionality is typically used to give users a means of finding members on the site. As your site grows, it becomes increasingly difficult to find the particular member information that your users are searching for.

One way to combat this issue is by providing filterable values that users can select to narrow their search and allowing them to more easily find the member that they are looking for. This code recipe gives you the functionality to do just that.

Full Directory (no filters selected)

Allow Users to Filter Results in your Member Directory

Filtered Directory View

Filtered View of PMPro Member Directory

Setting Up Your Member Directory Filter Widget

  1. 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.
  2. Add your filterable fields to the widget by updating the widget() function (specifically lines 36-90 at the time of writing).
  3. Update the SQL query based on user input into the fields you created in the my_pmpro_directory_widget_filter_sql_parts() function.
  4. Insert the widget into a sidebar shown on your Member Directory page via the WordPress Appearance > Widgets screen. This widget will not show any content on pages without the member directory shortcode.
  5. Test to make sure that your filters are working as expected.

The Code Recipes

This code recipe requires a premium membership plan.

View Pricing

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