CuirPig

extract_attachment_ids

May 18th, 2021 (edited)
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. function extract_attachment_ids($post) {
  2. $reslt=[];
  3. $attachments=wp_get_attached_media('',$post->ID);
  4. if (count($attachments)) {
  5. array_push($reslt, array_map(function ($o) {return $o->ID;},$attachments);
  6. }
  7. return $reslt;
  8. }
  9.  
  10. /* array for id of images to be deleted */
  11. $rosies_images_to_be_deleted = [];
  12.  
  13. $args = array(
  14.     'posts_per_page' => '999',
  15.     'post_type' => 'product'
  16. );
  17. $my_query = new WP_Query($args);
  18.  
  19. if ($my_query->have_posts()) {
  20.  while ($my_query->have_posts()) { $my_query->the_post();
  21. array_push($rosies_images_to_be_deleted, ... extract_attachment_ids($post));
  22. }
  23. ?>
  24.  
Advertisement
Add Comment
Please, Sign In to add comment