[Resolved] How To Get Notification Count? (Code)?
-
Hey,
I am trying to change the page title whenever there are notifications.
If a user has more than 0 notifications then it should show, ‘You Have New Notifications’.
I have tried out this code :
$notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), 'object' ); $count = ! empty( $notifications ) ? count( $notifications ) : 0; if ( $count>0 ) { add_filter('wp_title','my_page_title',10,1); function my_page_title($title){ $title='You Have New Notifications'; return $title; } }
But, it is not working. It is only working when I change the value of this code
$count = ! empty( $notifications ) ? count( $notifications ) : 0;
from 0 to 1,2 etc. Something like this,
$count = ! empty( $notifications ) ? count( $notifications ) : 2;
So, it is reading this end number as the number of notifications. I referred the notification code from here
How can I make this code work?
Thanks
Have a nice day!
- The topic ‘[Resolved] How To Get Notification Count? (Code)?’ is closed to new replies.