diff --git a/includes/core/class-member-directory-meta.php b/includes/core/class-member-directory-meta.php index dae20b37..8df10b14 100644 --- a/includes/core/class-member-directory-meta.php +++ b/includes/core/class-member-directory-meta.php @@ -959,7 +959,8 @@ if ( ! class_exists( 'um\core\Member_Directory_Meta' ) ) { } elseif ( 'last_login' === $sortby ) { $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_sort ON ( umm_sort.user_id = u.ID AND umm_sort.um_key = '_um_last_login' )"; - $this->sql_order = ' ORDER BY CAST( umm_sort.um_value AS DATETIME ) DESC '; + $this->joins[] = "LEFT JOIN {$wpdb->prefix}um_metadata umm_show_login ON ( umm_show_login.user_id = u.ID AND umm_show_login.um_key = 'um_show_last_login' )"; + $this->sql_order = $wpdb->prepare( ' ORDER BY CASE ISNULL(NULLIF(umm_show_login.um_value,%s)) WHEN 0 THEN %s ELSE CAST( umm_sort.um_value AS DATETIME ) END DESC ', 'a:1:{i:0;s:3:"yes";}', '1970-01-01 00:00:00' ); } elseif ( 'last_first_name' === $sortby ) { diff --git a/includes/core/class-member-directory.php b/includes/core/class-member-directory.php index 5ff16b8f..e462fc85 100644 --- a/includes/core/class-member-directory.php +++ b/includes/core/class-member-directory.php @@ -1464,17 +1464,33 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) { } elseif ( 'last_login' === $sortby ) { $this->query_args['orderby'] = array( 'um_last_login' => 'DESC' ); + // Please use custom meta table for better results and sorting. $this->query_args['meta_query'][] = array( - 'relation' => 'OR', + 'relation' => 'AND', array( - 'key' => '_um_last_login', - 'compare' => 'EXISTS', - 'type' => 'DATETIME', + 'relation' => 'OR', + array( + 'key' => '_um_last_login', + 'compare' => 'EXISTS', + 'type' => 'DATETIME', + ), + 'um_last_login' => array( + 'key' => '_um_last_login', + 'compare' => 'NOT EXISTS', + 'type' => 'DATETIME', + ), ), - 'um_last_login' => array( - 'key' => '_um_last_login', - 'compare' => 'NOT EXISTS', - 'type' => 'DATETIME', + array( + 'relation' => 'OR', + array( + 'key' => 'um_show_last_login', + 'compare' => 'NOT EXISTS', + ), + array( + 'key' => 'um_show_last_login', + 'value' => 'a:1:{i:0;s:2:"no";}', + 'compare' => '!=', + ), ), ); unset( $this->query_args['order'] ); diff --git a/readme.txt b/readme.txt index 517fbb3f..9db19f97 100644 --- a/readme.txt +++ b/readme.txt @@ -180,6 +180,7 @@ IMPORTANT: PLEASE UPDATE THE PLUGIN TO AT LEAST VERSION 2.6.7 IMMEDIATELY. VERSI * Fixed: YouTube validation when field value is empty * Fixed: Social URLs sanitizing where user can put his social username (e.g. Instagram, Facebook) * Fixed: Using only published forms and member directories IDs on predefined pages installation +* Fixed: Member Directory before query hook when custom meta table is active = 2.8.5 2024-04-09 =