Skip to:

Opened 5 months ago

Last modified 3 weeks ago

#8556 accepted defect (bug)

BP_Notifications_Notification::get - error for meta_query

Reported by: shawfactor Owned by: espellcaste
Milestone: Up Next Priority: normal
Severity: normal Version:
Component: Toolbar & Notifications Keywords: needs-patch needs-testing needs-unit-tests


Team I have identified an error with BP_Notifications_Notification::get

When you do a meta query using the above static method the notifciation id is no longer avilable in the result as it won't cast as an integer

my code:

$meta_query = array(


'key' => 'foo_key',
'compare' => 'NOT EXISTS',


$args = array(

'user_id' => $user_ids_array,
'meta_query' => $meta_query,
'per_page' => '1',
'order_by' => 'date_notified',

$notifications = BP_Notifications_Notification::get($args);

ithe issue saeems to be that it won't cats as an integer on line

$results[$key]->id = (int) $results[$key]->id;

Change History (3)

#1 @shawfactor
5 months ago

actually the problem is caused by the join which creates two id fields in the result. The fix is quite easy.

Simply change the original select statement to


$select_sql = "SELECT n.*";

So that only the $bp->notifications->table_name fields are selected

#2 @shawfactor
5 months ago

actually fixing this also requires patching the method get_where_sql in the same class to ensure that the id field is never ambiguous, when you do a join with the meta table.

Last edited 5 months ago by shawfactor (previous) (diff)

#3 @espellcaste
3 weeks ago

  • Component changed from Core to Toolbar & Notifications
  • Keywords needs-patch needs-testing needs-unit-tests added
  • Milestone changed from Awaiting Review to Up Next
  • Owner set to espellcaste
  • Status changed from new to accepted
Note: See TracTickets for help on using tickets.