-
-
Save sbrajesh/d71d88317c649333b9e456bf3ba8cf4f to your computer and use it in GitHub Desktop.
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
/** | |
* Get notification for use specific to a component. | |
* | |
* @param int $user_id user id. | |
* @param string $component_name component name. | |
* | |
* @return array|object|null | |
*/ | |
function bd_custom_get_grouped_notifications_for_user( $user_id, $component_name ) { | |
global $wpdb; | |
// Load BuddyPress. | |
$bp = buddypress(); | |
// SELECT. | |
$select_sql = "SELECT id, user_id, item_id, secondary_item_id, component_name, component_action, date_notified, is_new, COUNT(id) as total_count "; | |
// FROM. | |
$from_sql = "FROM {$bp->notifications->table_name} n "; | |
// WHERE. | |
$where_sql = $wpdb->prepare( "WHERE component_name = %s AND user_id = %d AND is_new = %d", $component_name, $user_id, 1 ); | |
// GROUP | |
$group_sql = "GROUP BY user_id, component_name, component_action"; | |
// SORT | |
$order_sql = "ORDER BY date_notified desc"; | |
// Concatenate query parts. | |
$sql = "{$select_sql} {$from_sql} {$where_sql} {$group_sql} {$order_sql}"; | |
// Return the queried results. | |
return $wpdb->get_results( $sql ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment