You cannot do this with wp_query, since the height and width do not have their own meta-fields (they are part of a serialized array). But this is easy enough to overcome, we can simply assign them our own postmeta db entry at boot time (you can also use wp_query to get all the images and cycle through to update existing images)
add_filter('wp_generate_attachment_metadata', 'add_metac', 10, 2); function add_metac($meta, $id){ update_post_meta($id, 'height', (int) $meta['height']); update_post_meta($id, 'width', (int) $meta['width']); return $meta; }
Then you can request larger images, etc., for example:
$types = array( 'image/jpeg', 'image/gif', 'image/png'); $args= array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => $types, 'meta_query' => array( 'relation' => 'AND', //-->this is default but showing here as you can use OR array( 'key' => 'height', 'value' => 300, 'type' => 'numeric', 'compare' => '>', ), array( 'key' => 'width', 'value' => 300, 'type' => 'numeric', 'compare' => '>', ), ) ); $images= new WP_Query($args);
source share