
Attachment next/previous
By:
duck__boy on
Nov 3rd, 2011 | syntax:
PHP | size: 0.88 KB | hits: 48 | expires: Never
function make_current_attachment_data_array($attachment_id){
$attachment_id = (int)$attachment_id;
$attachment = get_post($attachment_id);
$attachments = get_image_attachments($attachment->post_parent);
$previous = apply_filters('get_previous_post_where', get_adjacent_post(false, false, true));
$next = apply_filters('get_next_post_where', get_adjacent_post(false, false, false));
$attachment_data = compact(
'attachment',
'attachments',
'previous',
'next'
);
return $attachment_data;
}
add_filter('get_previous_post_where', 'filter_image_attachment_where');
add_filter('get_next_post_where', 'filter_image_attachment_where');
function filter_image_attachment_where($where){
global $post;
$where = str_replace('publish', 'inherit', $where);
$where.= " AND p.post_mime_type LIKE '%image%' AND p.post_parent = {$post->post_parent}";
return $where;
}