Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Create action running on trashed_post hook to modify post_meta value

wp_trash_post and trashed_post – from source:

function wp_trash_post($post_id = 0) {
    if ( !EMPTY_TRASH_DAYS )
        return wp_delete_post($post_id, true);

    if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
        return $post;

    if ( $post['post_status'] == 'trash' )
        return false;

    do_action('wp_trash_post', $post_id);

    add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']);
    add_post_meta($post_id,'_wp_trash_meta_time', time());

    $post['post_status'] = 'trash';
    wp_insert_post($post);

    wp_trash_post_comments($post_id);

    do_action('trashed_post', $post_id);

    return $post;
}

Related Posts:

  1. Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
  2. How to enqueue scripts on custom post add/edit pages?
  3. Unregister post type from child theme
  4. flush_rewrite_rules on save_post Does Not Work on First Post Save
  5. With what hook can I address all posts from all custom post types when they are published?
  6. What hook should be used to programmatically create a post only when master post is updated?
  7. How to register custom post types in a plugin?
  8. Remove “Get Shortlink” button in admin of custom post type
  9. update_post_meta() whenever custom post type is updated
  10. Can’t unregister parent theme’s CPT from my child theme
  11. Insert Multiple Post with Same Publish Button
  12. How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
  13. Filter Posts from the Main Query
  14. Using preg_replace to filter custom textarea
  15. Get rid of “trash can” for custom post type
  16. Use remove_meta_box conditionally on custom post type
  17. wp_trash_post action hook with custom post type
  18. How do I amend form data before it is saved for a custom post type
  19. How can I get some of a posts meta data whilst it is still inserting?
  20. How to recover the post ID earlier in the WP admin hook action “firing” sequence?
  21. Using `set_transient()` when saving a custom post type
  22. How to store additional data that is related to core data
  23. do action inside a class is not working
  24. Add a post when another post type is inserting
  25. Changing CPT permalink
  26. Creating a custom post type upon registration for a specific user role
  27. Update main post with same category when creating custom post to update the modified date
  28. Attaching more than 1 parent (Post) to a media file
  29. How to return/export only data showing on screen in custom post type view all screen
  30. Dynamic page for nav items used as filters
  31. Use WP_query to match post types based on custom field values
  32. Post Click Redirect to Custom URL instead of Single Post Page
  33. How to sort by multiple values in a nested WP_Query
  34. How can I add a meta[] to my custom post type and search by term with the Rest API?
  35. Show posts from WP Custom Post Type selected from a field in a metabox
  36. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  37. Peepso: Add extra data field (custom post meta) to postbox
  38. Where is get_post_meta value located?
  39. Hook create / update post
  40. How can I use a custom template to load custom post type posts based on a post_meta value
  41. Custom meta fields not showing up in WP_Response Object via custom endpoint
  42. How do I create a customised table list of a custom post type (in the admin area)?
  43. publish_post action callback not executed, why?
  44. How to get post by meta value
  45. Sort custom post archives by a meta value from a different custom post type?
  46. Bulk trashing post ‘fails’
  47. Change picture attachment meta of all occurrences of a picture
  48. Unknown Post Meta Records
  49. Get Previous Post based on Custom Field Name, for Custom Post Type
  50. Get meta values from parent post and save in child post
  51. Saving custom post types post_meta over REST-API fails
  52. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  53. How do I get all authors posts of a custom post type outside loop
  54. add action save post type and update post meta woocommerce
  55. How to Disable option of meta field if that option is selected for any other post in custom post type?
  56. get_post_meta not working with variable as a post_id for dynamically get the postid
  57. Custom Function to redirect singular post if specific meta field is empty
  58. Correct way to register custom post type from external php file?
  59. How to get post detail based on URL of the post
  60. Stored meta from attachment, video length?
  61. Custom post type meta fields missing on save_post_type
  62. How to save post_status using action save_post?
  63. WordPress deletes custom posts instead of trash them
  64. Saving Child Terms on front end not setting parent
  65. Custom post meta box as a sub form
  66. Linking posts together with Advanced Custom Fields “both ways”
  67. Order posts by meta value hiding posts instead of re-ordering
  68. Metaboxes in Loop
  69. Custom post type: “transition_post_status” action get title and other fields
  70. Add more custom fields when creating a new custom post type
  71. Keep br tags from stripping
  72. Grab meta data before post is saved
  73. call a function when insert and update a custom post type
  74. Custom meta box data not saving
  75. custom search results – order results differently by post type
  76. update a posts of other custom post type
  77. How do I extract the contents of a CPT’s custom field for all posts?
  78. Stripe multiple transactions
  79. Why does get_post() not return anything?
  80. Collect custom post in a calendar
  81. Storing data in a multidimensional array from dynamically generated foreach loop
  82. How to get Current week and current date record wp query
  83. How to get post meta for custom post type and taxonomy
  84. get_post_meta for Custom Post Type ( CPT )
  85. Execute code only after user clicks ‘update’ button for CPT being edited
  86. Delete custom post type metadata without deleting the post in admin area
  87. Edit is changing my custom’s post type parent id
  88. Order by post meta value gets random results
  89. Custom Fields as Post Type Options
  90. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  91. Adding Information To All Posts Screen
  92. Filter Content on all Post Types
  93. Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
  94. Disable Facebook Comments Automatically On CPT
  95. How to add post reference field to a plugin?
  96. Filter wp_dropdown_categories Per Post Type
  97. meta query always fails even if data is correct
  98. Problem with ‘save_post’ hook not running
  99. Customizing a plugin function using a hook
  100. WordPress custom post type
Categories custom-post-types Tags actions, custom-post-types, hooks, post-meta, trash
WP Custom Comment Callback Not Responding
Conditional tags issue for multiple is_page() conditions in sidebar.php

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress