Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Last active November 28, 2019 15:25
Show Gist options
  • Select an option

  • Save nikitasinelnikov/2fb1b30fcee35ded4935eb3d240331cb to your computer and use it in GitHub Desktop.

Select an option

Save nikitasinelnikov/2fb1b30fcee35ded4935eb3d240331cb to your computer and use it in GitHub Desktop.
Sorting by Last & First name
add_filter( 'um_members_directory_sort_fields', 'my_custom_sorting', 10, 1 );
function my_custom_sorting( $sort_fields ) {
$sort_fields['last_first_name'] = __( 'Last & First name', 'ultimate-member' );
return $sort_fields;
}
add_filter( 'um_modify_sortby_parameter', 'my_custom_sorting_handler', 10, 2 );
function my_custom_sorting_handler( $query_args, $sortby ) {
if ( $sortby != 'last_first_name' ) {
return $query_args;
}
$query_args['meta_query'] = array_merge( $query_args['meta_query'], array( 'last_name_c' => array(
'key' => 'last_name',
'compare' => 'EXISTS',
), 'first_name_c' => array(
'key' => 'first_name',
'compare' => 'EXISTS',
), ) );
$query_args['orderby'] = array( 'last_name_c' => 'ASC', 'first_name_c' => 'ASC' );
unset( $query_args['order'] );
return $query_args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment