Wordpress: custom post type delete post permanently

Asta :

So I want my posts in my custom post type deleted permanently instead of moving to trash first. so I found this code online that is supposed to do the trick. But I'm not able to get it to work somehow.

The code that I have is as follows.

function directory_skip_trash($post_id) {
    if (get_post_type($post_id) == 'directory') {
        // Force delete
        wp_delete_post( $post_id, true );
    }
}
add_action('wp_trash_post', 'directory_skip_trash');

The rest of the code of my custom post type itself u can find in this post that I've made earlier.

I'm probably missing out on something pretty simple.

UPDATE

so now it got it to kinda work. It does actually delete the post but I get this error. enter image description here after the error, if I return to the post page the post is gone and not in the trash anyone that might have a solution for it to just remove and not give this message?

disinfor :

Using the correct members post type:

You need to use the trashed_post hook. wp_trash_post happens BEFORE the post is trashed, so you're getting an error because the post didn't exist anymore.

function members_skip_trash($post_id) {
    if (get_post_type($post_id) == 'members') { // <-- members type posts
        // Force delete
        wp_delete_post( $post_id, true );
    }
}
add_action('trashed_post', 'members_skip_trash');

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=10520&siteId=1
Recommended