Title: PHP: Setting post ID to a variable
Last modified: August 19, 2016

---

# PHP: Setting post ID to a variable

 *  Resolved [dcroe05](https://wordpress.org/support/users/dcroe05/)
 * (@dcroe05)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/php-setting-post-id-to-a-variable/)
 * I’m trying to create an icon which will change with each post. I’ve got it working
   right now with a random number but I want to base the icon on the post number
   so the icons will rotate in a pattern.
 * In the following code the variable is not being set to the ID because the_ID()
   prints the post number. Is there a way to assign the post number to the variable?
 *     ```
       <?php
                 $numa = the_id();
                 echo $numa;
               ?>
       ```
   

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 9 months ago](https://wordpress.org/support/topic/php-setting-post-id-to-a-variable/#post-865016)
 * Use get_the_ID() instead.
 *  Thread Starter [dcroe05](https://wordpress.org/support/users/dcroe05/)
 * (@dcroe05)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/php-setting-post-id-to-a-variable/#post-865061)
 * Works great. Thanks a bunch.

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

The topic ‘PHP: Setting post ID to a variable’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [dcroe05](https://wordpress.org/support/users/dcroe05/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/php-setting-post-id-to-a-variable/#post-865061)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
