Skip to:
Content
Pages
Categories
Search
Top
Bottom

Given item_id, how can I get that activity’s author (user ID)?

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

  • shanebp
    Moderator

    @shanebp

    How are you getting item_id ?
    You probably already have the author ID in the same object or array that is providing the item_id, especially if you’re in a loop.

    You can always write a direct sql query: https://codex.wordpress.org/Class_Reference/wpdb


    FTLRalph
    Participant

    @ftlralph

    True that’s what I’m thinking too I’m kinda just testing my luck here hacking away at a “recent activity” plugin for BP

    It uses this line to get recent activity from the DB

    $recent_blogs = $wpdb->get_results( "SELECT user_id, content, item_id, id, date_recorded FROM {$wpdb->prefix}bp_activity WHERE TYPE = 'activity_comment' ORDER BY date_recorded DESC LIMIT $number_blogs" );

    Of course it gives the SELECTed stuff: user_id, content, item_id, id, date_recorded
    However that user_idis that of this particular activity (a comment, perhaps) whereas I’d like also the user_idof the activity being commented on (if that’s the case).

    I guess I was just thinking there was a bp_get_activity($item_id)->author,content,date etc type of function


    shanebp
    Moderator

    @shanebp

    In this context, item_id is related to the component.
    For example, if the component is ‘groups’, then the item_id is a group id.
    And secondary_item_id is kinda like another filter, maybe a comment_id.

    But custom-rolling an activity list is going to lead you, at some point, into a dead end.

    A much better approach is to use the many parameters of bp_has_activities.
    And maybe write some custom sql to gather data arrays to feed into that function.


    FTLRalph
    Participant

    @ftlralph

    Thanks, yeah I’m going to look into some SQL action to get what I want, I think I’m just thinking about it wrong

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar