Title: Get Post Id While Adding it to the database.
Last modified: August 19, 2016

---

# Get Post Id While Adding it to the database.

 *  [nigmatech](https://wordpress.org/support/users/nigmatech/)
 * (@nigmatech)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/get-post-id-while-adding-it-to-the-database/)
 * I am creating an interface to add/update posts from within my theme. I POST the
   form to the same page that uses **wp_insert_post();** in order to add it to the
   database and right after that uses **add_post_meta();** to add custom field.
 * I need to know post ID, hoeever, in order to run **add_post_meta();**, which 
   I do not know. I have looked through Google and Codex, but did not find an answer.
 * Please advise me how to find out ID of the post that I have just added (a certain
   way) or any other way to do what I want to.

Viewing 1 replies (of 1 total)

 *  Thread Starter [nigmatech](https://wordpress.org/support/users/nigmatech/)
 * (@nigmatech)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/get-post-id-while-adding-it-to-the-database/#post-1964688)
 * Please let me know if the question is not formulated well, I am new to WordPress
   coding and PHP

Viewing 1 replies (of 1 total)

The topic ‘Get Post Id While Adding it to the database.’ is closed to new replies.

## Tags

 * [$post->id](https://wordpress.org/support/topic-tag/post-id/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [nigmatech](https://wordpress.org/support/users/nigmatech/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/get-post-id-while-adding-it-to-the-database/#post-1964688)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
