9951 explained code solutions for 126 technologies


php-wordpressHow to get the post ID in WordPress using PHP?


The post ID in WordPress can be retrieved using PHP. To do this, the get_the_ID() function can be used. This function returns the post ID of the current post.

Example code

$post_id = get_the_ID();
echo $post_id;

Output example

123

Code explanation

  • get_the_ID(): This function returns the post ID of the current post.

Helpful links

Edit this code on GitHub