WordPress at a glance

the_ID() WP 0.71

Display the ID of the current post in the WordPress Loop.

Post ID in the loop can be also obtained through $post->ID. Sometimes it's easier and there is no unnecessary call of the function.

Works based on: get_the_ID()
1 time = 0.000403s = fast | 50000 times = 0.18s = very fast | PHP 7.1.2, WP 4.7.3

No Hooks.


Nothing (null). The post ID is displayed immediately.


<?php the_ID(); ?>


#1 Let's print the inscription "Post Number: 465" on the screen (for post 465)

<p>Post Number: <?php the_ID(); ?></p>

#2 HTML Anchor of the post

<h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>

Now the link to this anchor will be: http://site.com/link_to_post#post-465

in XHTML, the id attribute of an HTML tag cannot start with a digit. Therefore, you need to add at least one letter before the_ID().

Список изменений

С версии 0.71 Введена.

Code of the_ID() WP 5.5.1

function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
	echo get_the_ID();

Related Functions

From tag: WP Loop

More from category: Posts, pages...

More from Template Tags: Posts, Pages, ...

vladlu 100vlad.lu
Editors: kama 100
No comments
    Log In . Register