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:
- 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
- Hook for post and page load
- How do you use a CPT as the default home page?
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- Get post ID from wp_insert_post()
- WP insert post and custom taxonomy
- Filter for “get_post_type_archive_link()”
- Why The Init Hook For Custom Post Types
- How to show more posts on an archive page?
- Why get_next_post_link() or get_previous_post_link() doesn’t return the required links?
- How often do you need to register_post_type?
- How to create notification on frontend using heartbeat api for multiple custom post types
- How to set a custom post type post as static front page?
- Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!
- WordPress Custom Shortcode Conflicting with Media Library
- Hook when adding or editing a specific custom post type? [closed]
- Trying to save custom post type from frontend partially working
- Assign category to front end post
- Custom post type archive sorted and grouped by date in post meta field
- pre get posts changing the query
- Actions that Run on Admin Edit Page Load After Posts Are Queried
- WordPress tax_input only if logged in
- Programmatically adding posts
- Custom post_type search’s $wp_query->query_vars do not correspond
- Check Title Unique Or Not and If not error message and dont save
- Add html to cpt main page / admin edit.php
- register_taxonomy and register_post_type does not work [closed]
- How to auto increment post title & post slug field?
- Hooking in to an archive page?
- Insert Multiple Post with Same Publish Button
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Posts are duplicating on wp_post_update
- create parent post using wp_insert_post
- 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
- Add CPT values to Database
- Why cant I add a custom post type to a custom taxonomy?
- Categorise Custom Post Types
- Add a custom text to admin footer in a Custom Post Type page
- Programatically inserted posts not showing in Posts Table
- Custom Meta fields Update hook?
- Include php on a specific page template
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- sortable columns for multiple custom post types not working
- How to build a WordPress post review system beside commenting
- WordPress hook after post content and meta update
- providing access to post_id or post inside functions.php
- How to handle new post from API request?
- How to handle this specific case of custom post type?
- Make a custom column sortable by a value from a different custom post type
- wordpress post_where set only for my costum post type
- Loading plugin text domain before registering post type
- What hook can I use to modify custom post data before it is displayed on the page?
- Catch and display error on save_post action
- Update value inside array update_post_meta
- 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
- 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
- Update main post with same category when creating custom post to update the modified date
- 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?
- How to insert post 6 times after user register like ask.fm
- Keep br tags from stripping
- Submitting custom post from frontend,jQuery ajax, and custom validation – can’t find proper place to insert wp_insert_post()
- Execute code only after user clicks ‘update’ button for CPT being edited
- Adding Information To All Posts Screen
- Generate slug and meta data if meta field is empty
- Customizing a plugin function using a hook
- wordpress form processing to custom post type not working
- What is the proper way implement a global $wp_rewrite?
- Omitted Content After Post-Publish Insertion
- Dynamically change post_parent in every page load?
- How to string lines from the_content() hook in WordPress?
- Redirect drafted post of custom post type to URL?
- Modifying post_type_link hook messing up edit function for a custom post