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?
- Insert HTML inside link in a walker
- right_now_content_table_end function not working?
- WooCommerce product search titles only
- How to Separate CPT From Regular Posts?
- Remove rows in the manage post/page view
- Custom Taxonomy Permalinks Redirection
- Add custom column in custom post type edit page
- Is there a way to have the view link on manage posts page to open in a new window or tab?
- How to create custom boxes with text inside?
- How to add post_type=value when editing that post type in the WordPress admin?
- wp_insert_post generates endless posts
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Remove standard meta boxes from custom taxonomy
- Open Custom Post Type as PDF
- Using The REST API How To Pull All Custom Posts?
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- What’s the difference between same wp functions get_posts(); functions in different form?
- I did group my search results by post type, but how can i give each of them its own order?
- Dequeue scripts and styles only for specific custom post type
- Function to display custom post type on front page makes menu items dissapear
- custom post type not showing in menu
- Show the same Article Available in Other Categories
- Getting posts under the custom post type ui category
- Show category ID on custom post type
- Storing posts from query and accessing later via AJAX call
- If post has custom field then display css-class
- How to customize a permalink (URL) structure?
- Display only one post each WEEK
- Custom Post Type with Templates using Meta Boxes?
- List children on child post
- Can I list a custom post type within another custom post type in the admin area?
- Restrict custom post type from appearing with ?post_types=
- Change custom post type slug from plugin options
- Show custom post type filtered by category
- create parent post using wp_insert_post
- Turn on and off custom post type from admin?
- Missing Posts in Custom Taxonomy List
- Display random posts, but omit the post it is on?
- How do I do this with WordPress? Taxonomies?
- Disable block with taxonomies at post page
- I would like to have different styles for my posts based on the content of each post
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- Can’t edit custom post type
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Which post does a taxonomy term belongs to?
- List custom taxonomy specific to one custom post type
- Post image in WordPress not appearing on home page
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- Set URL link to featured image of custom post type
- Display Ad on Specific Categories
- Change CPT archive title
- AJAX load more for different custom post type loops
- Hiding posts by other users and non-logged in
- PHP variable not regenerating when publishing multiple posts at the same time
- On update or create post redirect to current post position in list
- I need to add endpoint for wordpress categories
- Update Post Meta for a logged in user
- Add custom field to Posts and sort by it
- Add custom post type settings to wordress default posts
- How to target a specific custom post type post and its all children and grandchildren?
- Featured image overlay when changing post status
- Get related posts of child term of custom post type
- Two Custom Post Types Many to Many Relationship
- Problem with displaying posts in the CPT category
- get_post_meta not working on publishing
- JS innerhtml changing style when using AJAX
- Redirect 404 page with ID in slug to associated page with same ID in slug
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- Display featured image from one CPT within another CPT query
- Show titles, date of all posts on single category page