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)
- Should we trust the post globals?
- Is post ID number always incremental n+
- get comments and get posts in loop
- Count singular post views automatically
- Looping through posts per category gives same posts for each category
- How to have different content in the loop and single
- Only display posts with comments
- Display Latest Post from all Categories
- custom wordpress post loop – hide iframe content
- Divide Loop Into Days & Categories
- Can I set and show “important” post in my blog?
- While in “the loop”, detect if a post is the most recent
- Getting current post ID in functions.php
- How to display different number of posts
- How to filter posts that belong to a specific category only if that is the only category
- WP Query – duplicated posts once including tags in search results
- Most recent post from another database
- wp_tag_cloud() and the_taxonomies() work but not the_tag()
- previewing my posts on static page?
- Show all posts in sidebar in single.php
- Split WordPress Latest Posts in Multiple Columns and Rows with one single loop [closed]
- Avoid duplicate post from same Taxonomy
- Alternate row and columns every X posts
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- How do I restart my loop with get_next_post()?
- Display posts with tag that matches current post title
- Category Foreach keeps looping?
- Posts will not display on page-mypage.php
- Trying to use AngularJS with WordPress without any API
- Pagination with an array of post objects?
- wp_posts table: safely remove unused columns to save database storage
- Multiple Loops Breaking Pages
- Archive template combined with post slider and regular posts
- Why this function doesn’t works without the_post?
- Bootsrap carousel for post
- Optimizing the blog loop
- Are post, page and category IDs unique to each other?
- Different number of posts per row in grid layout
- WordPress displays post on subcategory only
- Trying to query all posts in category 4
- Determine if ID is page or post and query the ID
- How to get post id of last approved comment?
- Defining ‘last’ class on foreach blog posts
- How to get the post id (of the parent custom custom type) in a loop inside a widget?
- Want to change the post every three days with in specific category
- get posts, run a custom query, and join the results
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- How can I get the last post while on the first post for pagination? As if it were infinite
- Manipulate query to show specific post
- Blog posts not displaying on blog posts page
- Display the latest post from some selected authors
- Advanced Post Display/Pagination/Ordering
- Keep post format class with isotope filter
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to get alphabetic listing x other posts, based on first letter post?
- Sort by category and then date?
- Loop not allowing infinite scroll after post per page limit
- Customise the appearance of 4 specific post ID’s within the loop?
- what template-part to call, to have my post in the center of the page?
- How do I create a template page to show 3 blog posts?
- Custom post order returning posts from other categories
- blog post displaying within older post – loop issue?
- WordPress current post functions inside loop doesn’t work anymore, are they incompatible with php 8.0?