Delete oldest wordpress post (SQL query)

I figured it out! Pretty simple actually.. You can replace post_date_gmt with ID depending on your needs. post_author != 1 will prevent the admin’s post from being deleted, so the menu links and pages will stay intact 🙂

function deleteOldestPost(){
    global $wpdb;
    $prefix = $wpdb->prefix;
    $wpdb->query("DELETE
        FROM ".$prefix."posts where post_author != 1  order by post_date_gmt asc limit 1");
}
add_action('publish_post', 'deleteOldestPost');

There will be some transient data, i.e. wp_term_relationships. Any of the database optimize plugins will get rid of them.