LoginSignup
0
0

More than 5 years have passed since last update.

Wordpress:投稿と一緒に使われている画像も削除する

Last updated at Posted at 2019-03-23

function.phpに記入します

add_action( 'before_delete_post', 'delete_post_attachment' );
function delete_post_attachment( $post_id ) {
  $args = array(
    'numberposts' => -1,
    'post_parent' => $post_id,
    'post_type' => 'attachment',
    'post_status' => 'any',
    'post_mime_type' => 'image'
  );
  $attachments = get_children( $args );
  foreach( $attachments as $attachment ) {
     wp_delete_attachment( $attachment->ID, true );
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0