I want to return the context_id of the media being displayed

In an effort to create a link back to the post that a media was uploaded to while viewing the lightbox for that media (single media view), I think I need to get the context_id of that media. When I var_dump() rtmedia(), I see an object where the value for context_id is contained. But I can’t figure out how to make it available to my template. (Whats more, running rtmedia() seems to make all the data disappear for the rest of the page). Needless to say, I only have a loose grip on what’s all going on here.

SO, is there a way to return context_id for use in my template during the single view of a media item? Is there a better way to achieve my goal of providing a link back to the post referenced by the context_id?

Thanks much!

@Dan_Braun this is what you will do,place this function on your rt-template-functions.php file


function your_custom_function () {
	global $rtmedia_media; 
	$media_context = $rtmedia_media->context;
	if ( ( $media_context == 'post' ) || ( $media_context == 'page' ) )  {
		return 'element_tag_a href=' . get_permalink( $rtmedia_media->context_id ) .'> post link element_tag_a';
	}	
}

the editor is substituting the a element tag for a real link, that’s why I used (element_tag_a) ,and then on your template file ( single_media.php),where you want the link to show echo the function like so.


<?php echo your_custom_function(); ?>

You have to echo the function within the loop for it to work…

I had to add some double quotes to the the anchor tag string, but this worked. Thank you much!!

Hi @Dan_Braun,

We are glad to know that your issue has been fixed.

Feel free to create new support request. As of now I m closing this ticket.

You are welcome. Thank you.