Advertisement
daymobrew

List all JPG attachements of a specific size

Feb 10th, 2018
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.  
  3. define('WP_USE_THEMES', false);
  4.  
  5. /** Loads the WordPress Environment and Template */
  6. require( dirname( __FILE__ ) . '/wp-blog-header.php' );
  7. ?><!DOCTYPE html>
  8. <html lang="en-US">
  9. <head>
  10. <meta charset="UTF-8" />
  11. <title>List JPG Files</title>
  12. <meta name="viewport" content="width=device-width, initial-scale=1" />
  13. </head>
  14. <body>
  15. <h1>List JPG files</h1>
  16. <?php
  17.  
  18. $args = array(
  19.     'post_type' => 'attachment',
  20.     'posts_per_page' => -1,
  21.     'post_status' => 'inherit',
  22.     //'post_parent' => null, // any parent
  23.     'post_mime_type' => 'application/jpeg',
  24.     );
  25. $query = new WP_Query( $args );
  26.  
  27. if ( $query->have_posts() ) {
  28.     echo '<ul>';
  29.     while ( $query->have_posts() ) {
  30.         $query->the_post();
  31.         $image_info = wp_get_attachment_image_src( get_the_ID(), '416size' );
  32.         echo '<li>', $image_info[0], '</li>';
  33.     }
  34.     echo '</ul>';
  35.     /* Restore original Post Data */
  36.     wp_reset_postdata();
  37. } else {
  38.     echo '<p>No attachments found.</p>';
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement