Title: Add some meta data to post inserted using wp_insert_post function
Last modified: August 19, 2016

---

# Add some meta data to post inserted using wp_insert_post function

 *  Resolved [levani01](https://wordpress.org/support/users/levani01/)
 * (@levani01)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/add-some-meta-data-to-post-inserted-using-wp_insert_post-function/)
 * I’m using wp_insert_post function to insert new post but I need to add some meta
   data to each post as soon as it’s inserted. How can I do that? Should I retrieve
   the most recent post id ofter the post is inserted and use the id or there is
   some simpler method?
 * Thanks

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/add-some-meta-data-to-post-inserted-using-wp_insert_post-function/#post-1345991)
 * > Should I retrieve the most recent post id ofter the post is inserted and use
   > the id or there is some simpler method?
 * That’s what I’d do, except that [wp_insert post will return the “ID of the post if the post is successfully added to the database”](http://codex.wordpress.org/Function_Reference/wp_insert_post)
   so you don’t have to retrieve the ID. You already have it. Just catch the ID 
   like so `$myinsertedpostID = wp_insert_post($whatever);` and check that it isn’t‘
   0’.
 *  Thread Starter [levani01](https://wordpress.org/support/users/levani01/)
 * (@levani01)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/add-some-meta-data-to-post-inserted-using-wp_insert_post-function/#post-1346147)
 * Oh, thank you very much, I new that everything would be much easyer. 🙂

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

The topic ‘Add some meta data to post inserted using wp_insert_post function’ is
closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [levani01](https://wordpress.org/support/users/levani01/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/add-some-meta-data-to-post-inserted-using-wp_insert_post-function/#post-1346147)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
