Created
June 15, 2022 09:49
-
-
Save champsupertramp/cf6e0bfbaa2691eabda172d7d67a6ff7 to your computer and use it in GitHub Desktop.
Ultimate Member - Display Profiles with Upcoming Birthdays in the Member Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('um_user_before_query','um_061522_show_upcoming_birthdays', 10, 2); | |
function um_061522_show_upcoming_birthdays( $query_args, $obj ){ | |
$directory_id = $obj->get_directory_by_hash( sanitize_key( $_POST['directory_id'] ) ); | |
if( 325 !== $directory_id ) return $query_args; | |
add_action( 'pre_user_query', function( $uqi ) { | |
global $wpdb; | |
$search_meta = $wpdb->prepare(" | |
ID IN ( SELECT user_id FROM wp_usermeta | |
WHERE meta_key = %s AND meta_value NOT LIKE '%". date("/m/d") ."%' AND ( | |
( DATE_ADD( meta_value, | |
INTERVAL YEAR( CURDATE() ) - YEAR( meta_value ) | |
+ IF( DAYOFYEAR( CURDATE() ) >= DAYOFYEAR( meta_value ) | |
,1,0) | |
YEAR) BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY) ) | |
) | |
)", 'birth_date'); | |
$uqi->query_where = str_replace( | |
'WHERE 1=1', | |
"WHERE 1=1 AND (" . $search_meta ." ) ", | |
$uqi->query_where ); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code doesn't work, it's confusing people