Buddypress how to sort Groups page alphabetically by default

By July 19, 2018 Buddypress, PHP, Wordpress

In this short blog post I’ll run over how you can sort the Groups index page in Buddypress alphabetically by default (i.e. on first load of page they will be ordered by group name).

Edit or override 2 of the Buddypress templates

You’ll need these in your theme:

wp-content/YOUR_THEMENAME/buddypress/groups/index.php

and

wp-content/YOUR_THEMENAME/buddypress/groups/groups-loop.php

If these templates don’t exist in your theme you’ll need to make copies of the 2 templates from the Buddypress plugin  ( find in buddypress/bp-templates/bp-legacy/buddypress ) and pop into your theme directory in a folder called buddypress. You might need to copy from your parent theme if they are used there ( this is because of the buddypress / wordpress template hierachy – you can look that up if you don’t understand this).

 

Changes in groups-loop buddypress template

Before the bp_has_groups function call you need to add:

and then change the bp_has_groups function to:

 

Changes in index groups template

find this section and change to have alphabetical first ( you could also use the selected attribute ):

 

And thats it job done. Remember Buddypress can save your select choices in the session, which can be confusing – so clearing the cache will help in this scenario.

 

 

 

Leave a Reply