you can use pre_post_update
action hook like so:
add_action('pre_post_update','post_updating_callback');
function post_updating_callback($post_id){
global $post;
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ($post->post_status == "publish"){
//do update stuff here.
}
}
Update:
instead of wp_insert_post()
use wp_update_post
like this:
//first get the original post
$postarr = get_post($post_id,'ARRAY_A');
//then set the fields you want to update
$postarr['post_title'] = "new title";
$postarr['post_content'] = "new edited content";
$post_id = wp_update_post($postarr);
this way you only need to specify the fields that were updated and never worry about stuff like what was the original post type.
Related Posts:
- Add a post when another post type is inserting
- How to enqueue scripts on custom post add/edit pages?
- Unregister post type from child theme
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- With what hook can I address all posts from all custom post types when they are published?
- How to register custom post types in a plugin?
- Remove “Get Shortlink” button in admin of custom post type
- Can’t unregister parent theme’s CPT from my child theme
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Filter Posts from the Main Query
- Use remove_meta_box conditionally on custom post type
- wp_trash_post action hook with custom post type
- How do I amend form data before it is saved for a custom post type
- WordPress hook which triggers on post import
- How can I get some of a posts meta data whilst it is still inserting?
- How to recover the post ID earlier in the WP admin hook action “firing” sequence?
- Using `set_transient()` when saving a custom post type
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- How to store additional data that is related to core data
- do action inside a class is not working
- Create action running on trashed_post hook to modify post_meta value
- Cron job for creating posts not excecuting properly
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How do I add a custom screen for a custom post type to be called from custom post row action?
- Custom post type suppress transition from future to publish
- How to checked selected category checkbox when my custom post inserted from frontend
- Limit number of custom posts per taxonomy
- Post author for revision not being set on update/insert
- using wp_update_post for updating custom post type
- Add CPT values to Database
- Why cant I add a custom post type to a custom taxonomy?
- Categorise Custom Post Types
- Using preg_replace to filter custom textarea
- How can I add a filter to a particular post format?
- Is there any way to get list of all possible filter hooks for all post types?
- Create new custom post and post category of same name
- Add a custom text to admin footer in a Custom Post Type page
- Get rid of “trash can” for custom post type
- wp_insert_post wrong post type [closed]
- Programatically inserted posts not showing in Posts Table
- Custom Meta fields Update hook?
- Include php on a specific page template
- Add an Outside Wrapper to my Header and Make it Full Width
- What do the numbers mean at the end of add_action(‘save_post’)…?
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- Running a wordpress action when a custom post type term (taxonomy category) is changed
- sortable columns for multiple custom post types not working
- How check if a post is saved from backend or frontend?
- Update post if exist from PHP
- How to build a WordPress post review system beside commenting
- WordPress hook after post content and meta update
- ACF for custom post type archive pages: which hook to use?
- Assigning alternate single-{cpt} template based on blog_id in multisite
- providing access to post_id or post inside functions.php
- Before saving post hook
- How to handle new post from API request?
- How to handle this specific case of custom post type?
- Creating alternate meta box context locations
- Make a custom column sortable by a value from a different custom post type
- Types plugin custom post add_action hooks
- wordpress post_where set only for my costum post type
- insert image with custom post type
- Loading plugin text domain before registering post type
- importing table data to custom post type
- add_action ‘init’ from inside a class for custom post types
- What hook can I use to modify custom post data before it is displayed on the page?
- comments hooks on custom post type
- Catch and display error on save_post action
- Update value inside array update_post_meta
- Limiting actions only to edit.php page for specific custom post type
- See if the email exists or not
- WP_Insert_Post creating duplicate posts when logged in
- Best way to fix bad count on All | Mine | Published
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- wp_set_object_terms creates taxonomies but does not add custom posts to it
- Add html tot CPT edit screen – no metabox
- wp_insert_post from XML feed only inserting first post
- Plugin Development using classes – Public & Private Callbacks
- Custom Post Type action on post update
- Show Post Types customized in Template Page
- In child theme, add CPT to custom taxonomy registered in parent theme
- Store a value in global scope after init hook is fired
- What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?
- Changing CPT permalink
- How do I find out which (page) template file my custom child post is looking for?
- Update main post with same category when creating custom post to update the modified date
- Dynamic page for nav items used as filters
- Post Click Redirect to Custom URL instead of Single Post Page
- wp_insert_post deleting previous post custom meta
- Hook create / update post
- publish_post action callback not executed, why?
- Sort custom post archives by a meta value from a different custom post type?
- Correct way to register custom post type from external php file?
- Published page but it is page not found
- How to insert post 6 times after user register like ask.fm
- wp_insert_post() creates duplicates with ‘post_status’ => ‘publish’
- automatic creation of custom post type articles
- Keep br tags from stripping
- call a function when insert and update a custom post type
- Submitting custom post from frontend,jQuery ajax, and custom validation – can’t find proper place to insert wp_insert_post()