On a project I require to keep only 10 latest posts on website and auto delete all other posts. So I came up with this function which triggers on post publish/update and I used `offset` parameter to exclude latest 10 items.

```
function wpse_auto_delete_posts( $post_ID ) {
  global $post;

  $delete_posts = get_posts( array( 'post_type' => 'post', 'offset' => 10, 'posts_per_page' => -1 ) );
  foreach ( $delete_posts as $delete_post ) : setup_postdata( $delete_post );
    wp_delete_post( $delete_post->ID, true );
  endforeach;
  wp_reset_postdata();

}
add_action( 'publish_post', 'wpse_auto_delete_posts' );

```

But it appears, `offset` didn't work here with `'posts_per_page' => -1` and it keeps deleting all posts. I thought of using Date query but it will also not work too because new posts are created very frequently.

Is there any way to select all posts except latest 10 or 5. So WordPress can process them and keep latest X posts.