Yes, this is how it is supposed to work. The global $post
variable is set quite early in the page load, at the wp
hook. As you can see from the hook order, this is before the loop starts.
Basically the $post
object exists independent from its actual content in the database, which you retrieve during the loop. It’s specifically meant to be accessible all the time during page generation.
Related Posts:
- Permalink Short code showing unnecessary link text inside the loop
- Show all posts in category
- Optimize CPT-function with a loop
- Post-Archive like a page in a specific subdirectory
- Display specific posts on home page
- The loop starting at a certain ID
- linking to post outside the loop
- WP_Query of Category Not Showing First Post
- If custom field is empty, use one from a previous post
- Cant’ Grab WordPress Built-in Posts Through Loop
- How come this loop is not working? [closed]
- Loop not showing first post
- Display in category ( taxonomy) a number of post that I want
- Get post category as a separate string and url
- Find out in which kind of archive am I
- Limiting the amount of posts retrieved by the loop
- Display 3 posts with different HTML markup using a loop
- Pagination for normal (standard) posts on a page with a custom loop?
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- I can’t find the relevant part of the loop in my theme file. How do I find the full content with “More…”
- posts going to 2 pages/categories only show up in 1
- How to repeat a loop after 4 posts [duplicate]
- Custom Post Type Single Loop Outputting Wrong Post
- Using the loop to set locations for all posts on a single google map
- adding my posts (author posts) in menu
- How to separate each individual blog post?
- How to view all posts (on site, not admin) that are uncategorized?
- Defining ‘last’ class on foreach blog posts
- Archieve page, Advertisement Every 3 Posts
- Highlighting Current Category in the Archive and Feeds page
- Get current taxonomy and display query accordingly
- How to show full post on home page
- Error while excluding a post from another loop (using its ID)
- Is there a way to define the $post var outside the loop?
- ACF flexible content block not showing on live site (works locally)
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Want to change the post every three days with in specific category
- Separate top level categories on archive-product.php by meta
- While loop in functions.php outputting the_title() of each post on frontpage
- Shortcode for Comments and Comment Boxes in Post Loop
- How to hide protected posts from archive?
- blog post not accesible on click [closed]
- Current post categories and subcatecories outside of the loop
- Redirect to custom post if custom archive page has just one result?
- Posts are not displaying on their category and tag page
- Multiple post in One Loop in wordpress
- Display specific posts based on an ID of another post
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- “read more” redirects to the wrong page
- Diffrent layout for posts [duplicate]
- How to show post views shortcode data for each post on Posts List Page?
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- Count singular post views automatically
- How to distinguish pages created by woocommerce?
- Moved a website and excerpts don’t work for old posts
- show loop id post , only first id can read
- How can I get the last post while on the first post for pagination? As if it were infinite
- show image gallery in archives or category page
- Prevent Archive URLs
- view a list of 3 future post, from the nearest to the most far
- Loop and output 4 rows of posts on home page
- Get posts from category from custom query
- Double loop output
- How to show category image if no featured image is set?
- Get post id outside loop : Notice: Trying to get property of non-object
- how to call recent post content in a loop ( only the content before read more tag)
- Retrieve posts inside foundation tabs and tab-content split by 3 per row
- Loop through all posts showing duplicates
- Can I Paginate Post after every 25 tag?
- Post being duplicated with foreach loop
- Alternative content between posts no repetition
- Start loop from specific post ID
- post->ID displays the same ID number for every post
- Display new posts categories in separated divs
- Show post excerpt
- How do I apply a wordpress function to something with no ID inside an archive page?
- Wp_query loop is not working as it should
- Show author bio box
- Maximum number of posts per page before affecting performance?
- Use special template for the first post in the loop
- Display post order ranking within wordpress loop
- Posts are not showing up on next page.
- Can the_post_navigation() be outside of the loop?
- Custom post type – Loop out in random order but same 15 to appear first… still random
- WordPress infinite post cycle
- WordPress infinite post cycle problem
- Page 2 has no posts?
- Problem with wp_insert_post()
- How to get all posts in gallery post format template
- How to control Post view count incresing in sidebar widget posts too?
- WordPress Request Post All Post ID in a Loop? [closed]
- List Authors For Current Category
- Show Posts By Custom Field
- List of authors posts minus very latest
- WordPress loop uses unmodified posts array, why?
- Querying multiple categories in the WP loop if one of the category IDs is dynamically obtained
- Disable archiving of old posts?
- Post are not showing up
- Add row after three columns
- Post Format problem