Getting the post ID outside the loop WordPress

Viewed 11

I used the function get_the_ID() to get the ID of current post in WordPress. My understanding was that the loop in WordPress starts with have_posts() based on the documentaton (https://codex.wordpress.org/The_Loop_in_Action#Begin_The_Loop).

However, I was able to get the correct post ID even before the call to have_posts(). Shouldn't I have gotten false?

I tried it on single.php and well as a specific page-specific.php file.

What is considered outside the loop in WordPress?

0 Answers
Related