phprockers-logo

Get current post id in wordpress

2 ways, we have to get current post id in wordpress
First way: 
global $posts;
$current_post_id = $posts->ID;
Second way:  

global $wp_query;
$current_post_id = $wp_query->post->ID;

0 comments:

Post a Comment