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.

Allow Users to Filter Results in your Member Directory

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 Recipe

This code recipe requires a Plus Account or higher.

View Membership Options

David Parker

This code recipe was written by our very own David Parker.

Comments (2)

Hi David,
Thank you SOOOO MUCH for this code. It was exactly what I have been looking for for some time. It works just perfect.

Can you please extend it with a reset button as well?

Hi there, happy to hear that this code is working on your site! There are two main ways that I would consider creating a reset button:
1. Add a button that links to your member directory page with no parameters being passed in through the URL. Since the filters in this code recipe are passed in via the URL, removing those parameters will remove all filters and “reset” the page.
2. Add a button that, when clicked, runs a Javascript function that goes through all the fields you’ve created and clears them.

If you have additional questions on how to implement this behavior on your site, we would be happy to help if you open a ticket on our Member Support page:

Leave a Reply

For faster support related to issues on your specific site please open a ticket in our members support area.

Your email address will not be published. Required fields are marked *