user3014233
user3014233

Reputation:

Wordpress get page id not post id

How to get page id not post id?

I'm tried these, but always get post id.

global $wp_query;
print $wp_query->get_queried_object_id();

global $post;
print $post->ID;

$wp_query->get_queried_object_id();

This questions also not resolving this issue.

Upvotes: 1

Views: 686

Answers (2)

Yash
Yash

Reputation: 919

Try using this outside the Loop.

global $post;
print $post->ID;

Upvotes: 1

Mayur Chauhan
Mayur Chauhan

Reputation: 731

@sevi WordPress stores page as a post, and you can get requested page id by <?php get_the_ID(); ?>

Upvotes: 0

Related Questions