The get_the_ID() function uses the global $post variable, which outside of the loop is sometimes equal to get_queried_object_id(). Within the loop, the $post variable is set to the current post within the loop.
As to why get_queried_object_id() is recommended outside of the loop, is because it does not use the global $post variable, so is less likely to be corrupted by loops.
Related Posts:
- How to get posts published between a date and today?
- Display all posts from specific categories on a page
- How to exclude latest x posts from a paginated query?
- Display content from a specific category
- Can’t show comments count per post outside loop
- Showing random content / pictures from earlier posts in a sticky post?
- How to Display Post View Count
- How would I get 1 latest post from a query for 5 posts?
- Inserting custom data to the_post() during loop
- How To Get Posts With A Specific Word
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Display all posts that were published before full post on single.php
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- How to order posts in an arbitrary order?
- Display Posts on Custom Page
- Wrong post title displayed from loop
- Get the amount of posts on a current page
- How to get posts published on the latest date?
- How to only publish posts with image in it
- WP_Query: Show 10 posts in date order, first three random
- Accessing Post ID Within Loop
- Display specific posts on home page
- The loop starting at a certain ID
- linking to post outside the loop
- Display 3 posts with different HTML markup using a loop
- How to show post views shortcode data for each post on Posts List Page?
- Use special template for the first post in the loop
- Modify WordPress loop after it has been run
- show latest authors blog post
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Adding a category at even positions on main loop with modified pagination
- How to inject a post within a loop
- View post with specific category id and name which I selected in the backend (drop-down option)
- Get page ID of page that is set as the posts page
- Get first post from wp_query
- Get the current post ID as a variable in Javascript
- Query posts distinct authors
- Why do I need to use The Loop on pages (inside page.php etc)?
- How to get previous 10 days post from a specific date – WP Query
- Display All Sticky Post Before Regular Post
- At my posts archive page, outside the loop, get_the_id() returns the top most post’s ID
- Specific loop in Shortcode
- Repost post on specific date every year
- Search widget breaks when using multiple loops?
- Filter Posts By Tag
- Contact form 7 post loop [closed]
- If Specific Post, Link Elsewhere
- Most recent post from another database
- Exclude newest post from category X but show rest
- Reset Popular post query?
- page.php showing loop of posts and not page content
- Post-ID in url differs from $post->ID
- Child_of not displaying all children posts.. via get_posts
- Display posts with tag that matches current post title
- Pagination with an array of post objects?
- wp_query random post
- How do I stop the loop from repeating in my category template?
- How many posts does the loop return?
- Possible to alternate between two loops
- How to get a post’s content? [closed]
- Second get_permalink inside loop points to wrong URL
- Why I can not I use the variable outside my function?
- Counter is skipping post when I still want it visible [closed]
- Use Click Image to Play Youtube Video in a WordPress Loop
- The_excerpt() doesn’t parse – how to change that?
- Trying to edit archive.php to only show post extract, with featured image
- Extracting relevant tags associated with that particular single post only
- Why this function doesn’t works without the_post?
- wp_query with ajax
- Custom posts listing widget always returns 1 extra result
- Show posts by quarter
- Get postlist for each category using query_posts?
- Cant’ Grab WordPress Built-in Posts Through Loop
- Pagination for normal (standard) posts on a page with a custom loop?
- How to get post id of last approved comment?
- Current post categories and subcatecories outside of the loop
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- “read more” redirects to the wrong page
- Count singular post views automatically
- Loop and output 4 rows of posts on home page
- Loop through all posts showing duplicates
- Manipulate query to show specific post
- List Authors For Current Category
- Display the latest post from some selected authors
- get “read more” with custom DB query like you would with WP Query
- How to show the posts list into a static page? Problems to use the loop into a static page
- How to use extract shortcode in loop?
- wordpress taxonomy results
- Displaying posts on Homepage
- Where are my posts linked to? I keep getting a Not Found Error, and I have no single.php page
- WordPress posts loop pagination – first page return 125 posts instead of 10 and the rest return 10
- The post order is different for logged-in and non-logged-in users? [closed]
- How do I show the post title if an advanced custom field hasn’t been used?
- wp trim function not working
- Can I get custom post items in select box (dropdown)
- Custom post order returning posts from other categories
- CSS code for “inserting a custom post divider” after each post
- Is it possible to use the_post 2 times in one loop