Title: post id number
Last modified: August 18, 2016

---

# post id number

 *  [dirvish](https://wordpress.org/support/users/dirvish/)
 * (@dirvish)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/post-id-number/)
 * Is there a way to get a post’s ID number w/o it being printed out? I tried the
   following:
 * <?php if (the_ID() == 2) echo “test”; ?>
 * and it printed out the ID number instead of ‘test’
 * I don’t see any other template tags that are applicable. Is there an easy way
   to pull it from the database?

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

 *  [Lorelle](https://wordpress.org/support/users/lorelle/)
 * (@lorelle)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/post-id-number/#post-155057)
 * I’m not an expert on this, but isn’t the whole point of the tag to get the ID
   number as a result and it sounds like you are trying to overwrite that function
   to make it result in “test”. I think there must be a better way to do this….
 *  [oriecat](https://wordpress.org/support/users/oriecat/)
 * (@oriecat)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/post-id-number/#post-155063)
 * Yeah, what do you want the number for anyway then? Maybe if we knew what the 
   goal was, then we could figure something out.
 *  Thread Starter [dirvish](https://wordpress.org/support/users/dirvish/)
 * (@dirvish)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/post-id-number/#post-155065)
 * I was trying to have an ad displayed after every fourth blog post (“test” would
   have been replaced w/ the ad code), I was going to use gmp_mod with the post 
   id number, but I f0und an easier way to do it:
 * <?
    if ($my_id == 0) { echo “<br><br><div align=center>”; include (‘ad.inc’);
   $my_id = 3; echo “</div><br><br>”; } else $my_id–; ?>
 * You can see it in action here: [http://certification.foundnews.com/](http://certification.foundnews.com/)
 *  [PJ Brunet](https://wordpress.org/support/users/knowingart_com/)
 * (@knowingart_com)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/post-id-number/#post-155788)
 * “I don’t see any other template tags that are applicable. Is there an easy way
   to pull it from the database?”
 * I would still like to know the answer to her original question…
 * $post_id doesn’t seem to work, and there’s no tag for the page slug either 🙁
 *  [PJ Brunet](https://wordpress.org/support/users/knowingart_com/)
 * (@knowingart_com)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/post-id-number/#post-155789)
 * Maybe I will need to extract the slug from the_permalink() ?
 * Sounds yucky… 😉
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/post-id-number/#post-155790)
 * `$post->ID`
 * That works within [The Loop](http://codex.wordpress.org/The_Loop).
 *  [PJ Brunet](https://wordpress.org/support/users/knowingart_com/)
 * (@knowingart_com)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/post-id-number/#post-155791)
 * I love you, it worked! Thanks.

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

The topic ‘post id number’ is closed to new replies.

 * 7 replies
 * 5 participants
 * Last reply from: [PJ Brunet](https://wordpress.org/support/users/knowingart_com/)
 * Last activity: [20 years, 4 months ago](https://wordpress.org/support/topic/post-id-number/#post-155791)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
