Codex tools: Log in
Retrieve the numeric ID of the current post. This tag must be within The Loop.
<?php get_the_ID(); ?>
This tag has no parameters.
The ID can be stored as a variable using
<?php $postid = get_the_ID(); ?>
get_the_ID() Can be used to provide a unique anchor in a script. For instance, a dynamically-generated drop down menu with actions for each post in an archive could have
<?php $id = get_the_ID(); $dropdown = "<select name='dropdown-".$id."' >"; $dropdown .= "<option id='option1-". $id ."'>Option 1</option>"; $dropdown .= "</select>"; ?>
<?php echo '<input type="hidden" name="activepost" id="activepost" value="'.get_the_ID().'" />'; ?>
If the ID is not called within PHP, then we can use the_ID rather than echo get_the_ID();
get_the_ID() is located in