Skip to content

Instantly share code, notes, and snippets.

@MaximeCulea
Created July 5, 2019 07:27
Show Gist options
  • Save MaximeCulea/3817e7cac5d325c68d07abc5c7c6825f to your computer and use it in GitHub Desktop.
Save MaximeCulea/3817e7cac5d325c68d07abc5c7c6825f to your computer and use it in GitHub Desktop.
BuddyPress hacks !
<?php
/**
* Manage to "group" by new notifications first but still order all notifications by date
* @author Maxime CULEA
*/
// inside the notifications loop
$args = [ 'is_new' => 'both', 'order_by' => 'mc_custom_notification_order', 'sort_order' => 'DESC' ];
if ( bp_has_notifications( $args ) ) {
// show notifications
}
// hook on the query to change the SQL request
add_filter( 'query', function ( $query ) {
if ( false !== strpos( $query, 'mc_custom_notification_order' ) ) {
$query = str_replace( 'mc_custom_notification_order DESC', 'is_new DESC, date_notified ASC', $query );
}
return $query;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment