post_types_to_delete_with_user filter

Filters the list of post types to delete with a user.

apply_filters( 'post_types_to_delete_with_user', string[] $post_types_to_delete, int $id )


This is filter hook , its filter the list of post types to delete with a user.
By using this hook we can delete the post and custom posts whenver a user is deleted.
Its consists of two parameters, one $post_types_to_delete ,second is $UserId.


  • $post_types_to_delete : (string[]) Array of post types to delete.
  • $id : (int) User ID.

Live Example

To run the hook, copy the example below.

 $post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id ); 
if ( !empty( $post_types_to_delete ) ) { 
   // everything has led up to this point... 

The following example is for adding a hook callback.

// define the post_types_to_delete_with_user callback 
function filter_post_types_to_delete_with_user( $post_types_to_delete, $id ) { 
    // make filter magic happen here... 
    return $post_types_to_delete; 
// add the filter 
add_filter( 'post_types_to_delete_with_user', 'filter_post_types_to_delete_with_user', 10, 2 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'post_types_to_delete_with_user', 'filter_post_types_to_delete_with_user', 10, 2 ); 

 Subscribe to our weekly newsletter below and never miss the latest updates in WordPress