[wp-trac] [WordPress Trac] #27015: WP_Query::get_queried_object() does not always work in 'pre_get_posts'
WordPress Trac
noreply at wordpress.org
Wed Feb 5 00:58:43 UTC 2014
#27015: WP_Query::get_queried_object() does not always work in 'pre_get_posts'
--------------------------+-----------------------------
Reporter: bcworkz | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Related: [[#26627]]
The referenced ticket fixes the situation for categories. Inline docs
indicate the method returns objects for the following query types:
'''category, tag, taxonomy, posts page, single post, page, author'''.
Some of these work, some do not. This became apparent from the forums:
http://wordpress.org/support/topic/get_queried_object-no-longer-working-
with-pre_get_posts-and-pretty-permalinks/
Props jeich
Test setup.
Trunk at !#27067 used. (and 3.7 for regression check)
Default setup of fresh install except for the following as plugin:
* Hook 'pre_get_get_posts' and dump get_queried_object return if it
is_main_query
* Add custom taxonomy and associate with posts
* Register CPT
Change permalink setting to complete CPT rewrite registration
Also modify the DB as follows to test various query types:
* Add a tag to the Hello World post.
* Add a custom taxonomy term to the Hello World post.
* Add a CPT post
The site was browsed through various pages using the default (none)
permalink, then the month and name permalink. The result of getting a
queried object was recorded:
|| ||=no permalink =||=month and name=||
||uncategorized category ||stdClass object ||stdClass object||
||tag archive ||NULL ||NULL||
||taxonomy term archive ||stdClass object ||stdClass object||
||CPT archive ||stdClass object ||stdClass object||
||single post ||NULL ||NULL||
||single CPT ||NULL ||NULL||
||page ||NULL ||WP_Post object||
||author archive ||WP_User object ||False||
||posts page ||WP_Post object ||WP_Post object||
NULLs indicate failure of `get_queried_object()`. Except for tag archive,
all NULLs returned are due to regression prior to 3.7. Why the tag archive
failed in 3.8 is unclear, but the proposed patch addresses this issue as
well as all other NULL returns.
For those that don't know, the reason for different results with pretty
permalinks enabled is different query vars are defined when rewrite rules
are applied. The default no pretty permalinks does not use rewrite rules
and the query vars can only be what is parsed from the request.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/27015>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list