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
- Difference between an archive and a page listing posts
- Do we still need to include a “if (have_posts())” in templates?
- Query *only* sticky posts
- Create an “All Posts” or “Archives” Page with WordPress 3.0?
- Cannot access current post’s ID in custom plugin
- Can’t show comments count per post outside loop
- Show a list of recently viewed posts to a user
- Alternate custom content in the loop
- Showing random content / pictures from earlier posts in a sticky post?
- Auto Refresh Post List after X seconds
- Display posts with comments closed, with pagination?
- Display all months with posts and inside each month show the 5 latest posts
- Related posts loop based on tags AND categories doesn’t work without at least one tag assigned
- Guest Author – How to display posts on /author/ archive page
- How To Get Posts With A Specific Word
- How to display posts on a static page? (like search loop)
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Displaying Latest Posts on a Page
- Display all posts that were published before full post on single.php
- WordPress Loop – Next 3 Posts
- problems with loading posts in a table-row
- Blog page pagination is not working after using the offset argument
- WP Query – Posts Per Page not working in combination with category__in
- More then one menu items are assigned with “current-menu-item” class
- List category posts alphabetically on archive.php
- Pulling in post category and children within category
- How to add tags (custom taxonomy) to post class css?
- Listing Specific Categories from Current Post with Depth
- How to exclude visited posts from loop
- How to display excerpt post on hamepage and archive pages?
- Only display sticky post or latest post in custom loop
- get_the_category listing in hierarchial order
- Exclude current custom post on single post
- add to end of post in the loop with plugin
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- Custom taxonomy archive page problem
- Loop don’t work within single.php page
- Custom Post Type archive
- Add custom text automatically on each post
- Getting blog pagination to work on page set as front page
- Make loop inside slider divisible [closed]
- Display current post position in Elementor Posts widget
- singular posts using archive styling
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- Some doubts about how the loop work (trying debugging it)
- Post-Archive like a page in a specific subdirectory
- If custom field is empty, use one from a previous post
- Get post category as a separate string and url
- Display 3 posts with different HTML markup using a 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…”
- How to repeat a loop after 4 posts [duplicate]
- 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?
- How to show full post on home page
- 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)
- 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
- Get posts from category from custom query
- How to show category image if no featured image is set?
- Get post id outside loop : Notice: Trying to get property of non-object
- Retrieve posts inside foundation tabs and tab-content split by 3 per row
- 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
- Display new posts categories in separated divs
- Custom post type – Loop out in random order but same 15 to appear first… still random
- WordPress infinite post cycle
- Page 2 has no posts?
- How to control Post view count incresing in sidebar widget posts too?
- WordPress Request Post All Post ID in a Loop? [closed]
- WordPress loop uses unmodified posts array, why?
- Add row after three columns
- Post Format problem
- Modify WordPress loop after it has been run
- Skip posts, but keep posts per page
- Multiple Post Repeat for Related Post Loop by Category
- index.php is only displaying current month’s posts?
- Loop doesn’t display posts. It displays a link to the home page instead
- Grab next post title in archive page
- Where should get_post_meta() go to get $post->ID get_post_meta() is empty and $post->ID & get_the_id() are working
- Getting posts from multiple users?
- How to organise post by category and date
- Show post if in category
- Adding a category at even positions on main loop with modified pagination
- Displaying categories items among posts
- How do I display the next 3 posts in the sidebar?
- The loop: more posts than I want to fit on one page
- Index.php is ordering posts strangely
- First post in loop displays twice
- Wrap every 2 posts
- Add author section on Author archive posts
- What function does the loop of displaying posts?