Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created June 30, 2012 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/3025221 to your computer and use it in GitHub Desktop.
Save wpsmith/3025221 to your computer and use it in GitHub Desktop.
Attachment Metadata Query
<?php
$args = array(
'post_status' => 'inherit', // Default status of attachments
'post_type' => array( 'attachment' ),
'meta_key' => '_wp_attachment_metadata',
'meta_value' => 'FinePix J10',
'meta_compare' => 'LIKE',
);
$attachment_query = new WP_Query( $args );
// The Title
printf( '<h2>%s</h2>', __( 'FinePix J10 Pictures', 'text_domain' ) );
// The Loop
if ( $attachment_query->have_posts() ) :
while ( $attachment_query->have_posts() ) : $attachment_query->the_post();
// Do Stuff
echo wp_get_attachment_image( $post->ID, 'thumbnail' );
endwhile;
endif;
// Reset Post Data
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment