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?
- Get current post id in functions.php
- 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?
- How to add a “publish” link to the quick actions
- Action hook ‘wp’ firing twice… why?
- Are all ID’s used unique?
- 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)?
- get post id in while loops outputting page id
- 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?
- Does an article (post) id ever change?
- the_posts filter been called multiple time
- Get post id in wordpress action?
- How can i do something after head like adding a hook for after head but before post
- How to get the post’s parent ID?
- 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
- Is there a better, more efficient way to get the post id outside the loop?
- 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
- How blog page in WordPress works : blog page retrieve first post 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
- Adding buttons to Add New Post and Add New Page
- Get ALL post ID’s export list (Only id’s. Php or sql not important )
- How to get next post ID?
- 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
- How to I retrieve the ID from the Posts page?
- Crazy Question – Updating Post ID
- 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
- Exists filter or action that change Add New Post link?
- 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
- Get a post’s ID
- 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?
- Get post slug and match with menu item slug to change css
- Run a function when a custom post is update?
- WordPress Post ids big increment
- the wp_post_update isn’t working all the time
- Send email to user when I publish a new post
- 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
- Grab meta data before post is saved