Take a look at WordPress’ Post Status Transitions hooks: https://codex.wordpress.org/Post_Status_Transitions
If you’ve added proper debugging (so that you die at the top of your hooked function) it sounds like you’re not hooking into the right action.
Since you’re adding some meta and checking for it to see if you should run again, you could hook into publish_custom-post-type
. Also, the status may be confusing. I see you’re trying draft, but that does not include new
or auto-draft
. Make sure you are confident about the previous status and the new status as well as the post_type.
Related Posts:
- Set posts of a custom post type to be private by default?
- How can I add dropdown widget/box to admin post page?
- Limit Authors to their Own Posts on front-end excluding admins
- Multiple Content Block
- Notice: Undefined index: suppress_filters
- Shortcode not working with post counter
- Changing default ‘posts’ parameters with register_post_type_args
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Allow users to create posts without logging in?
- How to assign classes to all elements?
- Showing custom post type categories in the menu
- WordPress notification if new post published
- Get post format
- Template code to split a post and print a custom field?
- Send post changes to set email addresses (not users or subscribers)
- Display author box on just certain category posts?
- redirect after submiting post for review
- What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?
- subtracting the current post form then whole loop, which is generating all CPT titles
- Post that populates itself (almost) automatically using data from imported excel file
- How to mark posts as visited
- Work and Display a Custom Post Type as a normal Post
- Featured image in custom post is being disabled
- How to make a non-public post on wordpress approval?
- Restrict custom post type to only site administrator role
- How to force one column layout on custom post type edit page?
- WordPress REST Create Post of Custom Type
- Limit the post for differents custom post type in the same wp_query
- How do I add a custom post type to the Featured Content in twenty fourteen theme?
- Assigning a role to a specific custom post type (and ignoring other post types)
- Custom post type loops with different page templates
- Display posts in random post types
- Display Custom Post Type in Recent Posts
- Allow Users Access to Custom Post Type Only
- Slug for standard post post_type
- How to get Custom Post ID by adding filter to child theme’s function
- How do I create an archive page for standard posts?
- Remove parent from custom post type
- When ‘is_post_type_archive()’ return true?
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- How To Enable Block Editor (Gutenberg) for Existing Post Type via functions.php
- Create a post in custom post type using field in registration form after users submit form
- right_now_content_table_end function not working?
- How to add post_type=value when editing that post type in the WordPress admin?
- Open Custom Post Type as PDF
- Update Post Meta for a logged in user
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- Get the category from custom post type
- Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?
- Prioritize posts in query by meta keys?
- Load Next Posts With AJAX not working with custom post type
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Add term to custom post type on draft
- Template not working for the custom Post type
- Is it a good idea to add a column to the posts table?
- Loop increase number
- Change Slug of a Custom Post Type
- Creating separate feeds for custom post types
- wordpress lists similar type of posts in a custom post type
- Auto post creation
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Easy reading or transfer of data from posts?
- list posts of two post types in a single template
- The loop does not show users
- Front-end Image Upload to Custom Meta Box
- Conflict in function to allow single post template based on category
- Invalid content when I try to import custom post type from the old template wordpress
- Why is my custom post content only viewable when signed into WordPress?
- Add a form in every post and save data in post meta
- Pagination not working in custom post type. Help
- Right way to store a large set of similar information on website? [duplicate]
- Create a post automatically if search result has zero results
- Limiting the Number of User Posts to Their Own Posts
- Correct way adding External classes to Custom Post type and output their methods to template
- Problem with multi checkboxes value in metabox?
- Assign a Post to a User
- Cannot save pages after migration
- News post with multiple permalinks? When opened from different page
- Rest Api not working with Iframe in form data
- Send mail to author when custom post type is saved
- Recovering data about custom post and taxonomy types
- Display title of all custom posts from same taxonomy term on a custom post template
- wordpress does not see the correct custom taxonomy hierarchy
- Use WP pagination functions on a custom page template
- is using “require_once” in wordpress theme affect the speed ???
- Rewrite url post_tag for custom post type
- Only show current category post
- WordPress Contents Migration
- Problem to get the link of the default ‘post’ post type like the orther custom types
- How to set class to “current-page” on the currently viewed single post within a CPT
- Getting wrong ID
- call_user_func_array() error after moving to another server
- How to make post page unique and show it on home page?
- Query Posts From Multiple Post Types
- WP Build-In Post selector for CPT
- How to hide home title on pages and posts?
- How do I hide single category post on my post page
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Sort ACF by custom taxonomy