WordPress Attachments with old images

To get all featured images belonging to a certain post type, you’d have to get all those posts and the loop through them to get the featured image. Like this:

$query = new WP_Query( array( 
  'post_type'     => 'yourposttype',
  'posts_per_page'=>-1,
  ));

$thumb_list = array ();
if ( $query->have_posts() ) {
  while ( $query->have_posts() ) {
    $query->the_post(); 
    $thumb_list[] = get_post_thumbnail_id();
    }
  wp_reset_postdata(); // resetting for the main query
  }

error code: 523