[wp-trac] [WordPress Trac] #31355: Custom hierarchical post type 404s when `get_queried_object` is called too early
WordPress Trac
noreply at wordpress.org
Sat Sep 12 03:27:35 UTC 2015
#31355: Custom hierarchical post type 404s when `get_queried_object` is called too
early
--------------------------+------------------
Reporter: gradyetc | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.4
Component: Query | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------
Changes (by boonebgorges):
* milestone: Awaiting Review => 4.4
Comment:
> Can we not set it to null, or unset it before we attempt to find it?
Setting it to 0 gives it a value, which seems incorrect if the query
hasn't been run, or if there is no queried object.
Ah. It took me a few minutes to wrap my head around this. I assume that
`$this->queried_object_id = 0` was originally introduced an attempt to
avoid PHP notices. Setting it to 0 means that it passes the `isset` check
here https://core.trac.wordpress.org/browser/tags/4.3/src/wp-
includes/query.php?marks=2610#L2606, which means that the request passes
the weird check on line 2634, which means that "AND ($wpdb->posts.ID = 0)"
gets appended to the `WHERE` clause of the query, which means that
everything breaks. (You all already probably traced this. I'm writing it
out here for posterity :) )
Changing the default value to `null` means that the `isset()` check
*fails* (as expected).
It's still weird that objects have been queried at all by this point, but
I think jazbek is correct that we can use `null` as a simple fix. gradyetc
also pretty much suggested this in the ticket description too :) Let's go
with it.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31355#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list