Custom Directories

With BP Profile Search you can customize your Members directory, and even create additional custom Members directories, using the [bps_directory] shortcode.

BP Profile Search uses directories as results pages. When you select a custom directory as the results page of a search form, the search results will be limited to members of the selected directory.

For instance, if you have a custom directory of members living in London, and select that directory as the results page of a search form, the search results will be automatically limited to members living in London.

Please note that [bps_directory] is not a standard shortcode. It replaces the whole page content area, and can be used in the standard Members directory page to customize the standard Members directory itself.

The following sections detail how to use the [bps_directory] shortcode. Click on the section title to show the section content.

A) Create a custom Members directory

1. Go to Pages -> Add New;
2. Enter the page title;
3. Enter the shortcode [bps_directory] in the page content area;
4. Publish your page;
5. Visit your new page, it should display a perfectly good Members directory.

B) Use a custom directory as the results page for a search form

1. Go to Users -> Profile Search and Edit your form;
2. Locate the Directory (Results Page) drop-down in the Form Settings box, and select your custom directory;
3. If you wish to put the form in your custom directory, select Add to Directory: Yes;
4. Update your form;
5. Use your search form, the search results should appear in your custom directory.

C) Add hidden filters to a Members directory

Hidden filters are useful to build specific Members directories. For instance, if you have:

— a field Gender with ID 35 and values Male and Female
— a field Status with ID 56 and values Married and Unmarried

you can build a directory of the married men using the shortcode:

[bps_directory field_35="Male" field_56="Married"]

The available filter types (or search modes) depend on the field content, see below. For a detailed explanation of all the search modes, see the Search Modes page.

Filter types for fields containing text:

contains: [bps_directory field_xy_contains="text to find"]
is: [bps_directory field_xy="text to find"]
is like: [bps_directory field_xy_like="text with wildcards"]

Filter types for fields containing a number:

is: [bps_directory field_xy="number to find"]
range: [bps_directory field_xy_range="from number, to number"]

Filter types for fields containing a date:

is: [bps_directory field_xy="date to find"]
range: [bps_directory field_xy_range="from date, to date"]
age range: [bps_directory field_xy_age_range="from years, to years"]

Filter types for fields containing a single value chosen from a given set (e.g. Drop Down Select Box and Radio Buttons types):

is: [bps_directory field_xy="value to find"]
is one of: [bps_directory field_xy_one_of="value1,value2,..,valueN"]

Filter types for fields containing a set of values chosen from a given set (e.g. Checkboxes and Multi Select Box types):

match any: [bps_directory field_xy_match_any="value1,value2,..,valueN"]
match all: [bps_directory field_xy_match_all="value1,value2,..,valueN"]

D) Add more sort options to a Members directory

The standard BuddyPress Members directory offers a few sort options in the Order By drop-down (Last Active, Newest Registered, Alphabetical).

To add the option to sort by a profile field, use the shortcode:

[bps_directory order_by=field_xy]

where xy is the id of the profile field you wish to use.

For instance, if you have two profile fields, City with id 2, and Graduation Date with id 3, the shortcode:

[bps_directory order_by=field_2]

adds the option City to the Order By drop-down.

When a visitor selects City from the Order By drop-down, the directory (or the search results if a search is active) will be sorted by city, ascending. At the same time, the value of the City field will be displayed in each member’s entry.

The sort direction is asc (ascending) by default, but you can specify desc (descending) or both (both directions), and you can add more than one sort option.

For instance the shortcode:

[bps_directory order_by='field_2 both, field_3 desc']

adds the options City ⇡, City ⇣ and Graduation Date to the Order By drop-down.

When a visitor selects Graduation Date from the Order By drop-down, the directory (or the search results if a search is active) will be sorted by graduation date, descending. If they select City ⇡ or City ⇣, the directory will be ordered by city, respectively ascending or descending.

E) Modify the standard Members directory template

Important note: If you are not using a child theme, you are strongly advised to create yours before proceeding. Follow the instructions in the Codex to create and activate your child theme.

A few steps are specific to the BuddyPress template pack you are using (legacy or nouveau).

1. Create a directory buddypress inside your active child theme directory

2. Create a directory members inside the new buddypress directory

3. (legacy) Copy the files index.php and members-loop.php from
wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members to the new buddypress/members directory

3. (nouveau) Copy the files index.php and members-loop.php from
wp-content/plugins/buddypress/bp-templates/bp-nouveau/buddypress/members to the new buddypress/members directory

4. Modify the new files index.php and/or members-loop.php to suit your needs

5. Visit your directories, they should reflect your template changes.

F) Create and use a new Members directory template

The above procedure E) modifies the standard BuddyPress Members directory and all your custom directories. If you prefer not to change the standard BuddyPress Members directory, and/or want to use different templates for different directories, follow the steps below.

A few steps are specific to the BuddyPress template pack you are using (legacy or nouveau).

1. Go to the buddypress/members directory you created in procedure E)

2. Copy index.php to index-2.php and members-loop.php to members-loop-2.php

3. (legacy) Edit index-2.php, locate the string ‘members/members-loop’ and replace it with ‘members/members-loop-2’

3. (nouveau) — nothing to do —

4. Modify the new files index-2.php and/or members-loop-2.php to suit your needs

5. Edit your custom directory page, and replace [bps_directory] with:
[bps_directory template='members/index-2, members/members-loop-2']

6. Visit your directory, it should reflect your template changes.

You can create as many new templates as you like, and of course you can replace the names index-2.php and members-loop-2.php with names of your choice, as long as you use them consistently as shown in the above steps.