I am trying to get the single post id inside the PHP function that was called by a shortcode.
Please help me to get the single post ID.
Thanks in advance!
CodePudding user response:
To get the ID of the current post, you can use the following code.
global $post; $post_id = is_object( $post ) && isset( $post->ID ) ? $post->ID : 0