For the plugin you need to make the function to clean the database.
Made the removal of posts:

$q = new WP_Query( ['posts_per_page' => -1, 'post_type' => 'post' ] ); if($q->have_posts()) while($q->have_posts()){ $q->the_post(); wp_delete_post($q->post->ID, true); } wp_reset_postdata(); 

But while the media files remain.
There is a function wp_delete_attachment() , but I don’t know how to get the id all media files stored in the database.

  • For cyclists - SeVlad
  • I don't need third-party plugins. I need my own =) - Ivashka
  • And the cycling religion does not allow the "third-party" code to look? - SeVlad
  • Well, there everything is deleted through the drop table. I do not need this. I only media files and posts. and leave the rest - Ivashka
  • The question is which media files? Attached to the posts - you can. And used in posts - it is necessary to parse the content. - KAGG Design

1 answer 1

 if($attachments = get_posts(['post_type' => 'attachment','numberposts' => -1,'post_status' => null])) foreach($attachments as $attachment) wp_delete_attachment( $attachment->ID, true ); 

everything is simple and without dancing with tambourines

  • So you banged in general all the pictures in the database, including those not related to remote posts. - KAGG Design
  • @KAGGDesign to read docks? wp-kama.ru/function/get_posts Make a selection according to the criteria you need. - Andrew ProjectSoft
  • @AndreyProjectSoft you did not understand my comment at all. My comment means: "the answer is bad." The author of the answer must correct his answer or delete it. - KAGG Design
  • @KAGGDesign I understood everything correctly. The direction given is correct. It remains only to modify the ideal. But it is already necessary to look in the main context of a particular case - Andrew ProjectSoft
  • @AndreyProjectSoft but if you understood everything correctly, then you shouldn’t suggest me to read the documentation. You first type one-tenth of my reputation here, and then come out with similar offers. - KAGG Design