If you wanted to do this for all post types, you’d simply do
define('EMPTY_TRASH_DAYS', 0);
see https://codex.wordpress.org/Trash_status#EMPTY_TRASH_DAYS_option.
But since you only want to do this for a custom post type, you will need to hook into ‘trashed_post’ like this:
add_action('trashed_post', function( $post_id ){
[...]
then check your trashed posts’ post type:
if ( get_post_type($post_id) === 'foo') {
and use wp_delete_post() with the ‘force delete’ parameter set to true on posts that turn out to be of your targeted post type:
wp_delete_post( $post_id, true );
}
});
I’d guess WordPress will then probably still show the ‘moved into trash bin’ message, even though it’ll appear to the user as if there was no trash bin and the post will indeed already be deleted entirely. So you might have to change the $labels that are passed to your register_post_type() call if that’s the case.
Related Posts:
- Create action running on trashed_post hook to modify post_meta value
- Hook for post and page load
- How to enqueue scripts on custom post add/edit pages?
- How do you use a CPT as the default home page?
- Calling a Function After New Post Creation for a WordPress Custom Post Type?
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- get_query_var() not working in pre_get_posts
- Unregister post type from child theme
- Filter for “get_post_type_archive_link()”
- How to add a button to custom post type’s posts-page
- How to hook into the CPT’s title placeholder?
- Remove Trash / Delete option for Custom Post Type / Taxonomy
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- Why get_next_post_link() or get_previous_post_link() doesn’t return the required links?
- Admin Post Update Redirection to Posts Screen
- How often do you need to register_post_type?
- How to create notification on frontend using heartbeat api for multiple custom post types
- How to set a custom post type post as static front page?
- With what hook can I address all posts from all custom post types when they are published?
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- Hook when adding or editing a specific custom post type? [closed]
- remove_action conditionally for Custom Post Type
- What hook should be used to programmatically create a post only when master post is updated?
- Error after deleting Custom Post Type with a function (no trash used)
- How to register custom post types in a plugin?
- Add information above a custom post type listing of all posts page
- Dynamically create/remove terms in taxonomy when custom post type is published/trashed
- Custom Role can’t trash Custom Post Type
- Remove “Get Shortlink” button in admin of custom post type
- Custom Blog Post Listing in Genesis Sample Child Theme
- Set a default category – if the user didn’t select one- before creating a post
- Can’t unregister parent theme’s CPT from my child theme
- Modifying date filter on admin page for custom post type to link to custom field
- Hooking in to an archive page?
- Add custom column in custom post type edit page
- Insert Multiple Post with Same Publish Button
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Validate custom fields before save using WordPress Rest API
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Posts are duplicating on wp_post_update
- Limit number of custom posts per taxonomy
- Filter Posts from the Main Query
- Categorise Custom Post Types
- How can I add a filter to a particular post format?
- Is there any way to get list of all possible filter hooks for all post types?
- Add a custom text to admin footer in a Custom Post Type page
- Use remove_meta_box conditionally on custom post type
- Custom Meta fields Update hook?
- wp_trash_post action hook with custom post type
- How do I amend form data before it is saved for a custom post type
- Add an Outside Wrapper to my Header and Make it Full Width
- sortable columns for multiple custom post types not working
- How check if a post is saved from backend or frontend?
- How to build a WordPress post review system beside commenting
- WordPress hook after post content and meta update
- ACF for custom post type archive pages: which hook to use?
- WordPress hook which triggers on post import
- Assigning alternate single-{cpt} template based on blog_id in multisite
- providing access to post_id or post inside functions.php
- Before saving post hook
- Script doesn’t trash custom post types. Instead it duplicates the post and generate new versions in the trash
- Creating alternate meta box context locations
- Make a custom column sortable by a value from a different custom post type
- wordpress post_where set only for my costum post type
- comments hooks on custom post type
- Catch and display error on save_post action
- How to recover the post ID earlier in the WP admin hook action “firing” sequence?
- How to display “Trash” in my custom post type?
- Using `set_transient()` when saving a custom post type
- Best way to fix bad count on All | Mine | Published
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- wp_set_object_terms creates taxonomies but does not add custom posts to it
- Add html tot CPT edit screen – no metabox
- Plugin Development using classes – Public & Private Callbacks
- Custom Post Type action on post update
- Show Post Types customized in Template Page
- In child theme, add CPT to custom taxonomy registered in parent theme
- Store a value in global scope after init hook is fired
- Changing CPT permalink
- Update main post with same category when creating custom post to update the modified date
- Dynamic page for nav items used as filters
- Hook create / update post
- Sort custom post archives by a meta value from a different custom post type?
- Bulk trashing post ‘fails’
- Correct way to register custom post type from external php file?
- How to store additional data that is related to core data
- WordPress deletes custom posts instead of trash them
- call a function when insert and update a custom post type
- Execute code only after user clicks ‘update’ button for CPT being edited
- Custom Fields as Post Type Options
- Adding Information To All Posts Screen
- do action inside a class is not working
- Filter Content on all Post Types
- Customizing a plugin function using a hook
- Hook only specific post type
- add comments custom fields after user is logged in
- How to string lines from the_content() hook in WordPress?
- Redirect drafted post of custom post type to URL?
- Modifying post_type_link hook messing up edit function for a custom post
- Change CPT Edit Target Link for Admin List