Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Created November 13, 2023 12:03
Show Gist options
  • Save nikitasinelnikov/146374bdc36f71707bb1437cade3c455 to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/146374bdc36f71707bb1437cade3c455 to your computer and use it in GitHub Desktop.
Ultimate Member v2. Default sorting as verified + last login
// Select this option https://imgur.com/VM2tJhv
// for getting show verified users and active users(last login recent) first in result
function um_custom_verified_last_login( $query_args, $sortby ) {
if ( $sortby == 'verified_first' ) {
if ( empty( $query_args['meta_query'] ) ) {
$query_args['meta_query'] = array();
}
$query_args['meta_query'][] = array(
'relation' => 'OR',
'verified' => array(
'key' => '_um_verified',
'value' => 'verified'
),
'unverified' => array(
'key' => '_um_verified',
'value' => 'unverified'
)
);
$query_args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => '_um_last_login',
'compare' => 'EXISTS',
),
'um_last_login' => array(
'key' => '_um_last_login',
'compare' => 'NOT EXISTS',
),
);
$query_args['orderby'] = array( 'verified' => 'DESC', 'um_last_login' => 'DESC' );
$query_args['order'] = 'DESC';
}
return $query_args;
}
add_filter( 'um_modify_sortby_parameter', 'um_custom_verified_last_login', 999, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment