Don't like ads? PRO users don't see any ads ;-)
Guest

Attachment next/previous

By: duck__boy on Nov 3rd, 2011  |  syntax: PHP  |  size: 0.88 KB  |  hits: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function make_current_attachment_data_array($attachment_id){
  2.         $attachment_id = (int)$attachment_id;
  3.        
  4.         $attachment = get_post($attachment_id);
  5.         $attachments = get_image_attachments($attachment->post_parent);
  6.         $previous = apply_filters('get_previous_post_where', get_adjacent_post(false, false, true));
  7.         $next = apply_filters('get_next_post_where', get_adjacent_post(false, false, false));
  8.  
  9.         $attachment_data = compact(
  10.                 'attachment',
  11.                 'attachments',
  12.                 'previous',
  13.                 'next'
  14.         );
  15.        
  16.         return $attachment_data;
  17. }
  18.  
  19. add_filter('get_previous_post_where', 'filter_image_attachment_where');
  20. add_filter('get_next_post_where', 'filter_image_attachment_where');
  21. function filter_image_attachment_where($where){
  22.         global $post;
  23.         $where = str_replace('publish', 'inherit', $where);
  24.         $where.= " AND p.post_mime_type LIKE '%image%' AND p.post_parent = {$post->post_parent}";
  25.         return $where;
  26. }