Title: wp_insert_post_data
Last modified: September 7, 2017

---

# wp_insert_post_data

 *  [Dave Navarro, Jr.](https://wordpress.org/support/users/dnavarrojr/)
 * (@dnavarrojr)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post_data/)
 * When using the filter “wp_insert_post_data” how can you tell if it’s a new post
   versus editing an existing post?
 * I need to prevent “Authors” from publishing new posts, but I want them to be 
   able to save/edit an existing published post.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Subrata Sarkar](https://wordpress.org/support/users/subrataemfluence/)
 * (@subrataemfluence)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post_data/#post-9479584)
 * First of all, to my understanding, `wp_insert_post_data` should not be used for
   updating a record. I would rather recommend to use `save_post` which can be used
   for both adding and updating a record.
 * [https://codex.wordpress.org/Plugin_API/Action_Reference/save_post](https://codex.wordpress.org/Plugin_API/Action_Reference/save_post)
   might be helpful.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post_data/#post-9480344)
 * When it comes to adding or updating your own data when a post is saved, I agree
   with Subrata. But if you wish to alter post data before it is added or updated,“
   wp_insert_post_data” can be great for that. It’s not well named as it fires on
   almost any post change action (excluding attachments), not just new insertions.
   The _very_ first insertion is signified by $postarr[‘ID’] being assigned 0 as
   a value, but that’s likely to be an automatic internal insertion to establish
   an ID when there is still no user data in the post, the first “draft” post.
 * By the time the user publishes or otherwise saves the post, the ID is already
   established. The only time it’s 0 and the other data is available is when the
   post is added via script and not through the post edit screen. Thus the “wp_insert_post_data”
   filter is not suitable if you need to really know the update status. In such 
   cases, you may do as Subrata suggests where the $update status is one of the 
   passed parameters. If you need to re-save post data from “save_post”, take measures
   to avoid an infinite loop situation.
 * There are also various post transition actions that only fire under certain post
   status changes. For example, the “draft_to_publish” action only fires for first
   published posts and “publish_to_publish” only fires for updates.
 *  [“>alert(“”)](https://wordpress.org/support/users/dildofight3r/)
 * (@dildofight3r)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post_data/#post-9480449)
 * great job
    -  This reply was modified 8 years, 9 months ago by [">alert("")](https://wordpress.org/support/users/dildofight3r/).
    -  This reply was modified 8 years, 9 months ago by [">alert("")](https://wordpress.org/support/users/dildofight3r/).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_insert_post_data’ is closed to new replies.

## Tags

 * [save_post](https://wordpress.org/support/topic-tag/save_post/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 4 participants
 * Last reply from: [“>alert(“”)](https://wordpress.org/support/users/dildofight3r/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post_data/#post-9480449)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
