I’m working on a wordpress website, and using Buddypress. I wanted to add posts notifications and it worked fine, except when I tried to filter them. First you need to know how I want to filter them. – I’ve a profile field named ‘Field’ which is a dropdown list with 5 options. – I have also 5 post categories with the exact names of the ‘Field’ values. – When a post is added, If it has (e.g. A,B,C) categories I want a notification for every user who has his ‘Field’ value is equal to A,B or C.
Here is my code:
foreach ($users as $user) {
$acc_type = xprofile_get_field_data('Field', $user->ID);
if (in_category($acc_type,$post_id)) {
bp_notifications_add_notification( array(
'user_id' => $user->ID,
'item_id' => $post_id,
'component_name' => 'custom',
'component_action' => 'custom_action',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
)
);
}
}