Created
July 5, 2019 07:27
-
-
Save MaximeCulea/3817e7cac5d325c68d07abc5c7c6825f to your computer and use it in GitHub Desktop.
BuddyPress hacks !
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
<?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