Getting the WordPress Post ID of current post
Try using this:
$id = get_the_ID();
In some cases, such as when you're outside The Loop, you may need to use get_queried_object_id()
instead of get_the_ID()
.
$post_id = get_queried_object_id();
global $post;
echo $post->ID;
You can use $post->ID
to get the current ID.