Fetch rtmedia images from BuddyPress activity stream


#1

Hi
I want to fetch the url of the image attached to a BuddyPress activity programmatically. Would you please guide me in the right direction?
Currently, I am trying to fetch activity details in “wp_head” action as following:

if (bp_is_current_component(‘activity’) ) {
$activity_id = $bp->current_action;
if ($activity_id) {
$get_act = bp_activity_get(array(‘in’=>$activity_id));
}
}

Thanks in advance.


#2

Hi Rajat,

Yes, if you have activity id than you can easily URL get attached media. For that you need to use RTMediaModel class. Check following code.

$activity_id = activity id here;  
$media_model = new RTMediaModel();  
$media_obj = $media_model->get( array( 'activity_id' => $activity_id ) );  

// use get_rtmedia_permalink function -> https://github.com/rtCamp/rtMedia/blob/master/app/main/RTMedia.php#L1021 and pass id from $media_obj, it will return the permalink of attached media.

#3

Hey Ritesh,
Thanks for your reply. I tried the above solution. But it returns an array with propertie ‘total’ => 0 for every activity.
Also, does your plugin get affected by caching plugins installed?


#4

Hi Rajat,

That’s strange. It should return all the media attached to the that particular activity.
Can you check what’s the SQL query it’s executing to fetch the media.


#5