Home > Net >  How to get single post id when calling a function using shortcode in WordPress
How to get single post id when calling a function using shortcode in WordPress

Time:10-05

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

  • Related