Title: get current post id?
Last modified: August 18, 2016

---

# get current post id?

 *  [roobottom](https://wordpress.org/support/users/roobottom/)
 * (@roobottom)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id/)
 * I have a single post on my homepage ( [http://www.roobottom.com](http://www.roobottom.com))
   and below this I have a custom script that get 5 of the most recent posts.
 * I need to know how to get the id of the post on the homepage so I can pass it
   to the recent post script so it’ll miss out that post from the top of the list
   and get the next five.
 * I know I could get this from the URL $p parameter, but i’m using permalinks.
 * any help would be great! Thanks

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

 *  [ptryk](https://wordpress.org/support/users/ptryk/)
 * (@ptryk)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id/#post-316479)
 * just a guess.. but I think you should be able to use ‘$post_id’ within the loop,
   passing the value of it to a variable. Then, use that variable as an exclusion
   within the custom get 5 recent post scripts?
 *  Thread Starter [roobottom](https://wordpress.org/support/users/roobottom/)
 * (@roobottom)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id/#post-316488)
 * I tried echo’ing the var $post_id in the loop, but nothing happened. This would
   be most useful if we could access the var’s for each database field for each 
   post with a variable!
 * Any other ideas? Thanks!
 *  [ptryk](https://wordpress.org/support/users/ptryk/)
 * (@ptryk)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/get-current-post-id/#post-316816)
 * I had a few moments.. gave it a go as well.. and well, I got nothing as well…
   I looked at a plugin I am using that uses the same syntax $post_id and although
   it works there, I can’t get it to work within the loop, so I am honestly left
   scratching my head… sorry. anyone else have any ideas?
 *  [aeioux](https://wordpress.org/support/users/aeioux/)
 * (@aeioux)
 * [20 years ago](https://wordpress.org/support/topic/get-current-post-id/#post-316949)
 * You can use <?php echo $post->ID ?> to output or use the current post ID.

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

The topic ‘get current post id?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [aeioux](https://wordpress.org/support/users/aeioux/)
 * Last activity: [20 years ago](https://wordpress.org/support/topic/get-current-post-id/#post-316949)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
