Timeline for Global $post value outside the loop
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 26 at 17:02 | comment | added | challet | Yes I know and it hasn't been answered. There is no such things as pointer in php … and even so : what would be the value pointed by the pointer ? | |
Apr 26 at 13:24 | comment | added | cjbj | Your are asking your first question again. The $post object is a pointer to database content. The pointer IS the value of the object. | |
Apr 26 at 9:18 | comment | added | challet | And when it exists without accessing the database, what value does it have ? | |
Apr 25 at 8:28 | comment | added | cjbj |
The $post object is an abstract thing. It points to content, but is it not itself the content. So it can exist without accessing the database. Just like a road sign that says "Paris, 50 km" assures you that Paris exists and tells you where to find it, without itself being Paris. The road sign $post is there form the beginning of the page load, but you will only find Paris when you follow it by using get_post or some other command anywhere in your template.
|
|
Apr 24 at 21:38 | comment | added | challet | I'm sorry, I'm confused. What do you mean not really ? And what value is it supposed to have other than null (or false, or anything that can be tested as not initialized) or a database record ? Of course a variable has no content before it exists. But my question is about that variable value in a block template but before the loop happens. | |
Apr 24 at 9:31 | comment | added | cjbj |
No, not really. If you approach a website, WordPress first looks at the url. This translates into a query (a post, page, category archive, and so on). That's where the global $post variable is created. Next there are filters that may change the query (for instance amount of posts on a specific category archive page). Only when all this is done the query is actually executed and content is derived from the database.
|
|
Apr 23 at 23:32 | comment | added | challet | So, it is related to the database content | |
Apr 16 at 8:47 | comment | added | cjbj |
It's a bit like Schrödinger's cat: it doesn't have a value until you open it. The loop is the normal way to open, but you can access it anywhere on the page. get_post will give you the first post of the query and get_posts all of them.
|
|
Apr 15 at 13:52 | comment | added | challet | What value is it supposed to have if it doesn't get its content from the database ? In my case it seems to still have a peek into the loop to retrieve its first item. | |
Apr 15 at 12:07 | history | answered | cjbj | CC BY-SA 4.0 |