You can use transition_post_status:
add_action('transition_post_status', 'wpse_handle_untrash');
function wpse_handle_untrash($new_status, $old_status, $post) {
// if the post was in the trash, but now is not
if($old_status == 'trash') {
// if you want, you can do something only for a certain post type
if($post->post_type == 'my-desired-post-type') {
// do something
echo '<script>alert(' . $post->ID . ');</script>';
}
}
}
If you can explain what you’d like to do when a post is untrashed, that will be helpful in getting you a solution to accomplish it. Is a JS alert what you’re ultimately hoping to achieve?
This question may give you some ideas.
Related Posts:
- Get the post_id of a new post
- Get page ID of page that is set as the posts page
- Is there a action hook for the “Empty Trash” button?
- Function to execute when a post is moved to trash .
- add action only on post publish – not update
- Are post ID’s reliable?
- How to validate XML-RPC post creation and cancel when needed?
- get all posts ID from a category
- Create posts on user registration
- Get the current post ID as a variable in Javascript
- Is post ID number always incremental n+
- How to publish a post with empty title and empty content?
- Action hook ‘wp’ firing twice… why?
- Count singular post views automatically
- $post->ID displays wrong ID
- At my posts archive page, outside the loop, get_the_id() returns the top most post’s ID
- Restrict access to the Trash folder in Posts
- Showing random content / pictures from earlier posts in a sticky post?
- Custom function for “Submit for Review” hook
- Undelete post (untrash)?
- Is there an action that is called when a post is restored from the trash?
- How can I display a specific user’s first published post?
- Undefined variable post_id in custom quick edit coloumn
- how “manage_posts_custom_column” action hook relate to “manage_${post_type}_columns” filter hook?
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- add_action not using ‘delete_post’ action with wp_delete_post
- Getting post id from wp_insert_post_data function?
- the_posts filter been called multiple time
- Get post id in wordpress action?
- Can a page_id and a post_id be same?
- How to run a function when post is edited or updated using publish post action?
- How to restore permanently trash page? [closed]
- When trashing a post, also trash related comments
- Create cron job without a plugin?
- How to generate numbers indistinguishable for the IDs of the posts
- Getting current post ID in functions.php
- Buddypress activity id
- Post-ID in url differs from $post->ID
- Why is my Blog Page ID == First Post ID?
- current post with current author
- Is it possible to change post id for an already added menu item in WordPress?
- Adding custom fields to bbpress reply form
- Get ALL post ID’s export list (Only id’s. Php or sql not important )
- How to access $post from a callback function
- Search results posts_orderby and ID
- Set static page/post from another blog on same network
- Copy post to separate database with “add_action(….)”
- Retrieve post ID from “querying” URL
- How to get a post’s content? [closed]
- Call Web Services on post first publish
- How to check if single.php has already called the_post_thumbnail function
- obtain the author id given the post id
- How to get ID of the page included with get_page()?
- Remove Featured Image & All Media Uploaded to the Post
- SQL Command for restoring trashed comments
- What does WordPress do if I save a post without content/title? [duplicate]
- Why I can not I use the variable outside my function?
- Divs appearing everywhere in post content
- retrieve the oldest post id
- Prevent posts with certain post_meta to be edited
- How to check in functions.php if there is data in a WP_Query?
- Update post meta within save_post action
- Automatically set post_parent value
- WP_Query custom field pass the post id
- Accessing Post ID Within Loop
- How do post IDs work in WordPress?
- Are post, page and category IDs unique to each other?
- The loop starting at a certain ID
- linking to post outside the loop
- Widget to show posts in the sidebar basing on its IDs
- Making posts permalinks consistent numbers
- How to get post id of last approved comment?
- How to get the post id (of the parent custom custom type) in a loop inside a widget?
- Actions to use when flushing cache (when posts are added / deleted / modified)
- Is there a way to know when a page has been updated and do some action only once?
- Run a function when a custom post is update?
- WordPress Post ids big increment
- the wp_post_update isn’t working all the time
- Is update_post_meta used when save_post action hook is invoked?
- Reuse old post ID for new post after deleting post
- Get post attachment with post id
- Count singular post views automatically
- How do I apply a wordpress function to something with no ID inside an archive page?
- Get from the dashboard the ID of the current post being edited
- Only get post_id [duplicate]
- Is it possible to completely replace a post with an action/filter?
- Surrogate ID for posts, is there an alternative field in the posts table?
- Hook To Get All Posts Deleted
- Is it possible to have dynamic post id # in add_menu_page()?
- Run Jquery Script after delete post in front end
- Trash a post, send associated comments into the trash bin (change status)
- Using Post ID and Page ID in same function
- unused post IDs
- Custom post page has attributes of latest post [closed]
- Action while post is being published
- Can I get custom post items in select box (dropdown)
- Do anything on post_status change [duplicate]
- What is $post->ID
- View post with specific category id and name which I selected in the backend (drop-down option)
- How to get post ID after removing that post?