When you add dropdown options in BuddyPress Profile Pro (like Employee Functions, Departments, Skills), they appear in the order you created them, not alphabetically. Adding new values later means manually rebuilding the entire list to maintain alphabetical order.
This code snippet automatically sorts all dropdown, selectize, checkbox, and radio button options alphabetically while keeping special values like "Other" and "None" at the end.
// Add this code to your theme's functions.php file
// Path: /wp-content/themes/your-theme/functions.php- Install "Code Snippets" plugin from WordPress repository
- Go to Snippets β Add New
- Title: "BuddyPress Profile Pro - Sort Dropdowns"
- Copy the code below (without the opening <?php tag)
- Save and Activate
- Install "WPCode" plugin
- Go to Code Snippets β Add Snippet
- Choose "Add Your Custom Code (New Snippet)"
- Select "PHP Snippet"
- Paste the code and activate
<?php
/**
* BuddyPress Profile Pro - Alphabetical Dropdown Sorting (Code Snippet)
*
* Add this code to your theme's functions.php file or use a code snippet plugin
* like Code Snippets, WPCode, or Advanced Scripts
*
* This snippet automatically sorts all dropdown, checkbox, radio button, and
* selectize field options alphabetically in BuddyPress Profile Pro
*/
// Initialize the alphabetical sorting
add_action('init', 'wbbpp_initialize_alphabetical_sorting');
function wbbpp_initialize_alphabetical_sorting() {
// Hook into both regular and network options
add_filter('option_wbbpp_profile_fields_settings', 'wbbpp_sort_field_options_alphabetically', 20);
add_filter('site_option_wbbpp_profile_fields_settings', 'wbbpp_sort_field_options_alphabetically', 20);
}
/**
* Sort field options alphabetically
*/
function wbbpp_sort_field_options_alphabetically($settings) {
if (!is_array($settings)) {
return $settings;
}
// Field types to sort
$sortable_types = array('dropdown', 'selectize', 'radio_button', 'checkbox', 'text_dropdown');
// Values that should always appear at the end
$values_at_end = array('Other', 'Autre', 'None', 'N/A', 'Not Applicable', 'Not Specified');
foreach ($settings as $group_key => &$group_fields) {
if (!is_array($group_fields)) {
continue;
}
foreach ($group_fields as $field_key => &$field_info) {
// Check if this field has options to sort
if (!isset($field_info['field_type']['type']) ||
!isset($field_info['field_type']['options']) ||
!is_array($field_info['field_type']['options'])) {
continue;
}
// Check if this field type should be sorted
if (!in_array($field_info['field_type']['type'], $sortable_types)) {
continue;
}
// Get the options
$options = $field_info['field_type']['options'];
$special_values = array();
$regular_options = array();
// Separate special values that should appear at the end
foreach ($options as $option) {
$found_special = false;
foreach ($values_at_end as $end_value) {
if (strcasecmp(trim($option), $end_value) === 0) {
$special_values[] = $option;
$found_special = true;
break;
}
}
if (!$found_special) {
$regular_options[] = $option;
}
}
// Sort regular options alphabetically
natcasesort($regular_options);
// Combine: sorted regular options + special values at end
$field_info['field_type']['options'] = array_values(
array_merge($regular_options, $special_values)
);
}
}
return $settings;
}Before:
Manager
CEO
Developer
Accountant
Intern
HR Manager
Other
After:
Accountant
CEO
Developer
HR Manager
Intern
Manager
Other (stays at end)
Before:
Sales
HR
IT
Finance
Marketing
None
After:
Finance
HR
IT
Marketing
Sales
None (stays at end)
// Add this inside the foreach loop, after checking field type
if (in_array($field_key, array('priority_level', 'custom_order'))) {
continue; // Skip these fields
}// Modify the $values_at_end array
$values_at_end = array(
'Other',
'Autre',
'None',
'N/A',
'Not Applicable',
'Your Value Here' // Add your custom values
);// Add this check before sorting
$fields_to_sort = array('job_title', 'department', 'skills');
if (!in_array($field_key, $fields_to_sort)) {
continue;
}- Go to WordPress Admin β BuddyPress Profile Pro β Fields Settings
- Check your field settings
- Common field names:
job_titleemployee_functiondepartmentskillscountrylanguages
- β Sorts dropdown, selectize, radio, and checkbox options
- β Case-insensitive natural sorting
- β Keeps "Other", "None", etc. at the end
- β Works with multisite
- β No database changes
- β Easy to remove/disable
Not working?
- Clear all caches (browser, WordPress, CDN)
- Check if BuddyPress Profile Pro is active
- Verify the field type is supported
Wrong order?
- Check for extra spaces in option values
- Ensure special values match exactly (case doesn't matter)
- Original admin order is preserved (sorting only affects frontend)
- Works with profile edit and registration forms
- Compatible with AJAX-loaded content
- No performance impact on large lists
- BuddyPress Profile Pro: 2.5.0+
- WordPress: 5.0+
- PHP: 7.0+
- Works with BuddyBoss Platform
Save hours of manual list management with automatic alphabetical sorting!