Title: Getting post ID using function
Last modified: August 19, 2016

---

# Getting post ID using function

 *  Resolved [whiteh](https://wordpress.org/support/users/whiteh/)
 * (@whiteh)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/getting-post-id-using-function/)
 * Hey guys. I’m building my own theme for WordPress, and am still a bit new to 
   this so I need a bit of help 😀
 * I have a feature I built into the template that allows the user to email the 
   current page to a friend, it’s a plugin, and the way it works is collecting the
   User ID and sending them to another page like:
 * [http://domain.com/email/?id=5](http://domain.com/email/?id=5)
 * It works, but I want to have the same thing happening somewhere else on the template,
   hence I need to copy what the plugin does and put it in a new a tag if you know
   what i mean. Problem is the plugin uses PHP for everything and I can’t for the
   life of me see how it gets the post ID.
 * SO, if anyone knows how I can get the post id (not the permalink) for the current
   post I’d be extremely grateful 🙂
 * Cheers!

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/getting-post-id-using-function/#post-994404)
 * Most times it is `$post->ID` or might try `$id`.
 *  Thread Starter [whiteh](https://wordpress.org/support/users/whiteh/)
 * (@whiteh)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/getting-post-id-using-function/#post-994517)
 * THANK YOU! 😀
 * echo $id
 * ^ works like a charm 😀
 *  [ittekudasai](https://wordpress.org/support/users/ittekudasai/)
 * (@ittekudasai)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/getting-post-id-using-function/#post-994787)
 * I’m using WordPress 2.7.
 * I’m following the instructions [http://codex.wordpress.org/Template_Tags/wp_list_pages](http://codex.wordpress.org/Template_Tags/wp_list_pages)
 * but the $post->ID is returning a number that doesn’t work — actually a revision
   instead of the original post. THe original was id=33 (I checked the DB).
 * There was a revision ID=151 – and this is the number $post->ID gives me.
 * However, using wp_list_pages(“child_of” . $post->ID) doesn’t work. While it should
   return 151 because that is the last revision, WP doesn’t think that 151 has any
   child pages, because it doesn’t list anything.
 * What am I missing? I didn’t think it would be that hard to list sub pages.

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

The topic ‘Getting post ID using function’ is closed to new replies.

## Tags

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

 * 3 replies
 * 3 participants
 * Last reply from: [ittekudasai](https://wordpress.org/support/users/ittekudasai/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/getting-post-id-using-function/#post-994787)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
