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.
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)
Filtered Directory View
Setting Up Your Member Directory Filter Widget
- 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.
- Add your filterable fields to the widget by updating the
widget()function (specifically lines 36-90 at the time of writing).
- Update the SQL query based on user input into the fields you created in the
- 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.
- Test to make sure that your filters are working as expected.
The Code Recipe
This code recipe was written by our very own David Parker.