Skip to:
Content
Pages
Categories
Search
Top
Bottom

How would I get the thread link, or parent activity id, given the comment ID?

  • Avatar of godavid33
    godavid33
    Participant

    @godavid33

    I have attempted to retrieve the activity object using bp_activity_get_specific() and variations thereof, with no luck. My findings are that I can infact use that function to retrieve an activity, but this activity cannot be a comment or else an empty array is returned.

    What’s going on with that? That seems kind of pointless. But that aside, how can I get the parent activity ID, or more to the point, the thread link given the comment ID?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Avatar of henrywright
    henrywright
    Moderator

    @henrywright

    bp_activity_get_specific() should be used like this:

    // get activity
    $activity_get = bp_activity_get_specific( array( 'activity_ids' => YOURACTIVITYID ) );
    
    // single out the activity
    $activity = $activity_get[0];
    
    // grab specific activity item
    $activity_body = $activity->content;

    Ref: http://buddypress.org/support/topic/gettinng-id-of-the-activity-status/#post-112943

    Avatar of godavid33
    godavid33
    Participant

    @godavid33

    @henrywright I have already tried that, but it returns an empty array. As I mentioned earlier, if I supply the ID of a non-comment activity, I get results. No results with activity comments.

    Still need help with this :/

    Avatar of godavid33
    godavid33
    Participant

    @godavid33

    I am going to open a trac ticket. I believe this is a bug.

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    You should state the versions of BP & WP being used.

    You can always query the db directly.
    In this case, probably:

    global $bp, $wpdb;
    $wpdb->get_var( "SELECT secondary_item_id FROM {$bp->activity->table_name} WHERE id = $comment_id ");

    or maybe

    global $bp, $wpdb;
    $wpdb->get_var( "SELECT item_id FROM {$bp->activity->table_name} WHERE id = $comment_id ");
    Avatar of godavid33
    godavid33
    Participant

    @godavid33

    Arg, I always forget.

    BP 2.0, WP 3.9

    I am actually doing exactly that @shanebp! I also added that on the trac ticket I created

    Avatar of godavid33
    godavid33
    Participant

    @godavid33

    I was incorrect, it’s not a bug. The solution (thanks to @r-a-y) is this:

    
    $act_item = bp_activity_get_specific( array(
        'display_comments' => true,
        'activity_ids' => ACTIVITY_COMMENT_ID
    ) );
    

    Closed trac ticket can be viewed here https://buddypress.trac.wordpress.org/ticket/5592#comment:4

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    Nice – and obvious :)

    Querying the db directly should be avoided if possible – [laziness and bad habit].

    Avatar of godavid33
    godavid33
    Participant

    @godavid33

    Yeah, I generally try to avoid it which is why I was trying so hard to find the correct solution :D

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

You must be logged in to reply to this topic.