Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. function restrict_media_library_by_width($query) {
  2. $include = array();
  3. $exclude = array();
  4. $temp_query = new WP_Query($query);
  5. if($temp_query->have_posts()) {
  6. while($temp_query->have_posts()) {
  7. $temp_query->the_post();
  8. $meta = wp_get_attachment_metadata(get_the_ID());
  9. $meta['mime-type'] = get_post_mime_type(get_the_ID());
  10. if(isset($meta['mime-type']) &&
  11. ($meta['mime-type'] == 'image/jpeg' && isset($meta['width']) && $meta['width'] >= 100) ||
  12. $meta['mime-type'] == 'image/svg+xml') {
  13. $include[] = get_the_ID();
  14. } else {
  15. $exclude[] = get_the_ID();
  16. }
  17. }
  18. }
  19. wp_reset_query();
  20.  
  21. $query['post__in'] = $include;
  22. $query['post__not_in'] = $exclude;
  23.  
  24. return $query;
  25. }
  26. add_filter('ajax_query_attachments_args', 'restrict_media_library_by_width');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement