Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is it possible to get the item ID from notification objects?

  • Avatar of godavid33
    godavid33
    Participant

    @godavid33

    I’m trying to allow users to take action on notifications on the fly. Thusly, I need the ID for, say, the friend request but all I have is the notification ID. Can I get the friend request ID from the notification ID?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Avatar of godavid33
    godavid33
    Participant

    @godavid33

    I swear, probably 80% of my posts result in me solving my own damn problem.

    Inside your notification loop, if you can not see the item_id when using print_r on the notification object (returned by bp_core_get_notifications_for_user($uid, ‘object’) ) then call this function on the notification ID: bp_notifications_get_notification( $notif->id )

    The object this returns contains the item_id (print_r it to see what’s up).

    Hope this helps someone

    Avatar of henrywright
    henrywright
    Participant

    @henrywright

    Hi @godavid33

    I’m 99% sure you can. I do believe it’s store in secondary_item_id.

    I think you can access it by doing something like this:

    $notifications = BP_Notifications_Notification::get( array(
        'id' => $notification_id,
        'user_id' => $user_id
    ) );
    
    // I assume there will only be one result but i'll do a loop anyway
    if ( $notifications ) {
        foreach( $notifications as $notification ) {
            // this should output the friendship ID
            echo $notification->secondary_item_id;
        }
    }
    Avatar of henrywright
    henrywright
    Participant

    @henrywright

    Oops, didn’t see your second post. Glad you solved the problem!

    Avatar of shanebpdev
    shanebp
    Participant

    @shanebp

    @godavid33

    Did you try:
    bp_get_the_notification_item_id()
    from
    \buddypress\bp-notifications\bp-notifications-template.php

    Avatar of godavid33
    godavid33
    Participant

    @godavid33

    No @shanebp I didn’t try that, though I probably will. I don’t see why it would be any different than my soluton though.

    I am now presented with the problem of getting the parent activity id of a comment though, if y’all know how to solve that :P

    **EDIT: I tried your method Shane, but it didn’t work since I am not instantiating a loop, but a using an informal foreach and thus need to be able to pass the id of the notif**

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.