This will do the trick!
add_action('trash_post','my_trash_post_function',1,1);
function my_trash_post_function($post_id){
if(!did_action('trash_post')){
// do stuff
}
}
Here we add the function, and to prevent the hook from executing more than once using did_action:
http://codex.wordpress.org/Function_Reference/did_action
As always, these kinds of hooks take the form {post_status}_{post_type}
, so trash_post
, trash_page
, trash_customposttype
, publish_page
etc
Related Posts:
- How to publish a post with empty title and empty content?
- Create cron job without a plugin?
- How to check in functions.php if there is data in a WP_Query?
- Is there a action hook for the “Empty Trash” button?
- How to detect single.php (but not single-portfolio.php)?
- add action only on post publish – not update
- Create posts on user registration
- disable WP automatically inserted line breaks after an image
- delete post also attachments
- Action hook ‘wp’ firing twice… why?
- Restrict users from editing post based on the age of the post
- Code to auto expire posts after 30 days
- List only child categories a post is in, of a specific parent category
- How to change post status from publish to draft using hook in wordpress?
- Custom colors for post rows based on post meta value
- Custom wp_trim_words() function not trimming right
- Get the post_id of a new post
- How to display post tags
- Custom function for “Submit for Review” hook
- Allow role to delete posts but block him the wp-admin
- Why does `url_to_postid` return 0 when testing `page_for_posts` Page?
- WP_Query in functions.php overrides global $post object, even with wp_reset_query()
- Delete Post From Front-End and attachment permanently
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- Function to show random posts from a category
- How can I list random authors from current post category?
- Disable single post page
- the_posts filter been called multiple time
- Enabling post thumbnails for custom post type
- How to run a function when post is edited or updated using publish post action?
- How to generate numbers indistinguishable for the IDs of the posts
- Action hook for new pending posts?
- Uppercase first sentence in every post
- Ajax posts filter by date, comments, top views, top likes
- Prepend or add an Image to the content of a Post
- Why content_arr[‘extended’] removes paragraph tags?
- How to display the link (title) and thumbnail post?
- Force the “Choose from the most used tags” meta box section to always be expanded
- How to access $post from a callback function
- How to do set post permalinks using 6 digit random unique function?
- Display post x of y within category
- WordPress Automatic Filename Changer
- Copy post to separate database with “add_action(….)”
- Call Web Services on post first publish
- disable Tab post on nav-menus page (Admin)
- What does WordPress do if I save a post without content/title? [duplicate]
- Adding bootstrap classes to video shortcodes
- Every second post different class in blog view
- Get post meta retrieving wrong value
- The_excerpt() doesn’t parse – how to change that?
- Divs appearing everywhere in post content
- Prevent posts with certain post_meta to be edited
- Add custom text automatically on each post
- Defined function isn’t showed on page
- Update post meta within save_post action
- Automatically set post_parent value
- Getting Whitescreen when publishing a post [closed]
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- Related Posts: Changing Function For Posts Per Page
- Same post appears in related Posts?
- Help on conditional statement to accompany wp_insert_post function please?
- Set Default Post as Parent Child (Nested) Relation
- how to show comments only author which send own posts in wordpress
- get category in list of posts // shortcode for custom related posts
- Is there a way to know when a page has been updated and do some action only once?
- Alt text attributes not showing over portfolio images
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- Function is printing twice – any suggestions?
- Set a post expiration and delete a post when expirate
- Count singular post views automatically
- I want to change the WordPress comments file
- Replace Tag Keyword With Link Within Post Content
- Excluding tag Link from html tags in Post content
- Changing a users posts to drafts upon role change
- Get post id outside loop : Notice: Trying to get property of non-object
- How can i take all ids from untrash_post action?
- Show all posts from the tags without having to set all of them
- Trim excerpt to first paragraph
- im trying make a function to auto correct posts when i open the posts in the backoffice
- How to change number of posts shown on homepage vs other pages?
- Hook To Get All Posts Deleted
- Show only top 3 posts from 3 categories in order on home page
- How to edit label_submit styling?
- How to get posts from network blog
- Get post title by Alphabet
- How can I create a menu items from meta box based on users input
- How to use wp_editor(); in functions.php then retrieve content in the template
- How *not* to show the last post on the latest posts list
- How do we display a certain category type on a page while hiding all others?
- save_post not working
- wp trim function not working
- Insert Shortcode exactly at the end of the content
- Action while post is being published
- display last post modified date in genesis child themes
- Do anything on post_status change [duplicate]
- What function does the loop of displaying posts?
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- Show Next/Previous without Link
- Filters do not work when there are multiple (one works)