Changeset 12980
- Timestamp:
- 11/27/2023 12:27:16 AM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/wporg-memorial-profiles.php
r12974 r12980 12 12 global $wpdb; 13 13 14 $results = $wpdb->get_results( 'SELECT user_id FROM bpmain_bp_xprofile_data WHERE field_id = "476" AND value = "Yes"', ARRAY_A ); 14 $date_of_passing_field_id = 483; 15 $memorial_name_field_id = 484; 15 16 16 $user_ids = wp_list_pluck( $results, 'user_id' ); 17 $query = $wpdb->prepare( 18 ' 19 SELECT field_id, value, user_id 20 FROM `bpmain_bp_xprofile_data` 21 WHERE field_id IN ( %d, %d ) 22 AND user_id IN ( 23 SELECT user_id 24 FROM bpmain_bp_xprofile_data 25 WHERE field_id = 476 AND value = "Yes" 26 ) 27 ORDER BY user_id 28 ', 29 $date_of_passing_field_id, 30 $memorial_name_field_id 31 ); 17 32 18 // Grabs user display_name and user_nicename for profile link. 19 return get_users( 33 // Execute the prepared statement 34 $profile_data = $wpdb->get_results( $query, ARRAY_A ); 35 36 $user_ids = wp_list_pluck( $profile_data, 'user_id' ); 37 38 // Grabs user display_name, user_nicename, ID for profile link. 39 $users = get_users( 20 40 array( 21 41 'blog_id' => 0, 22 42 'include' => $user_ids, 23 43 'fields' => array( 24 ' display_name',44 'ID', 25 45 'user_nicename', 26 46 ), 27 47 ) 28 48 ); 49 50 // Add meta each user in the result 51 foreach ( $users as &$user ) { 52 foreach ( $profile_data as $profile ) { 53 if ( $profile['user_id'] === $user->ID ) { 54 55 if ( $date_of_passing_field_id === (int) $profile['field_id'] ) { 56 $user->date_passing = $profile['value']; 57 } 58 59 if ( $memorial_name_field_id === (int) $profile['field_id'] ) { 60 $user->display_name = $profile['value']; 61 } 62 } 63 } 64 } 65 66 // Sort based on date of passing 67 usort( 68 $users, 69 function ( $a, $b ) { 70 $timestampA = strtotime( $a->date_passing ); 71 $timestampB = strtotime( $b->date_passing ); 72 73 if ( $timestampA === $timestampB ) { 74 return 0; 75 } 76 77 // Use the less than operator for ascending order, or greater than for descending order 78 return ( $timestampA < $timestampB ) ? -1 : 1; 79 } 80 ); 81 82 return $users; 29 83 }
Note: See TracChangeset
for help on using the changeset viewer.