Advertisement
phpface

Untitled

Jan 11th, 2022
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. function streamtube_delete_child_video_posts( $postid, $post ){
  2.     if( in_array( $post->post_type, array( 'video', 'attachment' ) ) ){
  3.         $child_posts = get_posts( array(
  4.             'post_parent'       =>  $post->ID,
  5.             'post_type'         =>  'attachment',
  6.             'posts_per_page'    =>  -1
  7.         ) );
  8.  
  9.         if( $child_posts ){
  10.             foreach( $child_posts as $child ){
  11.                 wp_delete_attachment( $child->ID, true );
  12.             }
  13.         }
  14.     }
  15. }
  16. add_action( 'before_delete_post', 'streamtube_delete_child_video_posts', 999, 2 );
  17. add_action( 'delete_attachment', 'streamtube_delete_child_video_posts', 999, 2 );
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement