Custom media loop in profile page with php code

Hi,
I want to create a custom media loop in profile page so I can get only images link of the current member. I’ve tried with this code but it is showing this error Call to a member function have_media() on a non-object in /home/proacmatchmil/public_html/wp-content/plugins/buddypress-media/app/main/controllers/template/rt-template-functions.php

`<?php if ( have_rtmedia () ) : ?>

    <ul class="rtmedia-list rtmedia-album-list">  

        <?php while ( have_rtmedia () ) : rtmedia () ; ?>  

           <li> <a href ="<?php rtmedia_permalink (); ?>" title="<?php echo rtmedia_title (); ?>">  
        <img src="<?php rtmedia_image ( 'rt_media_thumbnail' ); ?>" alt="<?php echo rtmedia_title(); ?>">  
    </a></li>  

        <?php endwhile ; ?>  

    </ul>  
<?php endif; ?>`

Please help urgently.

Thanks.

Hi nazmur,

Try following code,

function get_member_media_links() {  
	if( $user_id = bp_displayed_user_id() ) {  
		$model = new RTMediaModel();  
		$results = $model->get( array( 'media_type' => 'photo', 'context' => 'profile', 'context_id' => $user_id ) );  
		if ( $results ) {  
			foreach( $results as $image ) {  
				$link =  get_rtmedia_permalink( $image->id );  
            }  
        }  
    }  
}

It will get links of all the images of a member.

Thanks. But it is giving me media page link like this http://www.matchmillion.com/members/admin/media/3/ but I need the image src link like http://mydomain.com/myimage.jpg

Is it possible to get?

Thanks.

Yes, it is possible.

Use following line,
$src = wp_get_attachment_image_src( $image->media_id, ‘rt_media_thumbnail’ );

It will get the image src.

Thanks. Is it possible to show Edit and Delete button for each media in the custom media loop. I’ve tried using rtmedia_actions() and it is showing buttons but clicking those not producing any output. Here is my full code

<?php if( $user_id = bp_displayed_user_id() ) {  
		$model = new RTMediaModel();  
		$results = $model->get( array( 'media_type' => 'photo', 'context' => 'profile', 'context_id' => $user_id ) );  
		if ( $results ) {  
			foreach( $results as $image ) {  
				$link =  get_rtmedia_permalink( $image->id );  
				//echo $link;  
				$src = rtmedia_image ( 'rt_media_single_image', $image->id,false );  
				echo "
  • ";
            rtmedia_actions();  
            }  
        }  
    } ?></code></pre>  
    

    Thanks.

    Yes, I think edit link will work properly but delete won’t work as you need to make an ajax post request with “/delete”.
    Ex. {site_name}/members/xyz/media/124/delete