I've replaced all attachment URLs from for example ?attachment_id=124 to media-view/124
I'm then using the following code to intercept and display the right content when someone goes to a media-view link.
function xhtml5responsive_query_parse( $query ) {
if ( strpos($_SERVER['REQUEST_URI'], 'media-view/') !== false ) {
$explode = explode ( 'media-view/', $_SERVER['REQUEST_URI']);
$id = rtrim($explode[count($explode)-1], '/');
if (is_numeric($id)) {
$query->query_vars['cat'] = -2; // Exclude my featured category because I display that elseware
$query->query_vars['posts_per_page'] = 5; // Show only 5 posts on the homepage only
$query->query_vars['attachment'] = true;
$query->query_vars['attachment_id'] = intval($id);
$query->in_the_loop = true;
$query->is_attachment = true;
}
}
}
The problem though is that it redirects media-view/124 to ?attachment_id=124
How can i make it just display the appropriate attachment instead of redirecting to attachment_id=124
Thanks.