Advertisement
Guest User

wordpress - get array of attachment IDs

a guest
Dec 22nd, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. ////  We use $gallery_media as an array containing all attachment IDs that have been approved by the admin before
  2.     $args = array(
  3.         'post_type' => 'attachment',
  4.         'posts_per_page' => -1,
  5.         'orderby'          => 'post_date',
  6.         'order'            => 'ASC',
  7.         'post_status' =>'any',
  8.         'post_parent' => $post->ID,
  9.         // This queries a custom field I created for media attachments – can be either 'piúblished' or 'pending'
  10.         'meta_query' => array(
  11.             array(
  12.                 'key' => 'attachment_status',
  13.                 'value' => 'published',
  14.             )
  15.         )
  16.         );
  17.     $attachments = get_posts( $args );
  18.     if ( $attachments ) {
  19.         $gallery_media = array();
  20.         foreach ( $attachments as $attachment ) {
  21.             // Check if attachment has been reviewed and custom status is "published"
  22.             // Put together our array
  23.             $gallery_media[] = apply_filters( 'id' , $attachment->ID );
  24.         }
  25.     }
  26.  
  27. // Outputs an indexed array containing attachment IDs according to our query
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement