Basically I am running those two outside the WordPress loop:
$wp_query->posts[0]->ID
get_the_ID
The first one returns of course the ID
of the first post. The second one returns the ID of either the first post or the last one. I would love to know why.
Basically I need to know information about the first post when I am in the header, which is why I was trying to use get_the_ID
. I cannot enter the loop at this stage.
Any help will be highly appreciated.
global $post;
echo get_the_id($post->ID);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.