[wp-trac] [WordPress Trac] #26627: Regression: get_queried_object no longer working with pre_get_posts and pretty permalinks
WordPress Trac
noreply at wordpress.org
Sat Dec 14 18:03:41 UTC 2013
#26627: Regression: get_queried_object no longer working with pre_get_posts and
pretty permalinks
--------------------------+-----------------------------
Reporter: Otto42 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.8
Severity: normal | Keywords:
--------------------------+-----------------------------
Plugin code to demonstrate the issue:
{{{
function test( $query ) {
if ( ! $query->is_main_query() )
return;
if ( $query->is_category('uncategorized') ) {
var_dump($query->get_queried_object());
die;
}
}
add_action( 'pre_get_posts', 'test' );
}}}
Now visit /category/uncategorized on a default install with any form of
non-default (pretty) permalinks configured.
Result in 3.7, it dumps this object and dies:
{{{
object(stdClass)#95 (15) { ["term_id"]=> &string(1) "1" ["name"]=>
&string(13) "Uncategorized" ["slug"]=> &string(13) "uncategorized"
["term_group"]=> string(1) "0" ["term_taxonomy_id"]=> string(1) "1"
["taxonomy"]=> string(8) "category" ["description"]=> &string(0) ""
["parent"]=> &string(1) "0" ["count"]=> &string(1) "1" ["cat_ID"]=>
&string(1) "1" ["category_count"]=> &string(1) "1"
["category_description"]=> &string(0) "" ["cat_name"]=> &string(13)
"Uncategorized" ["category_nicename"]=> &string(13) "uncategorized"
["category_parent"]=> &string(1) "0" }
}}}
Result in 3.8: The is_category check returns false and no object is
dumped.
Removing the is_category check reveals that the get_queried_object returns
NULL.
Note that switching to default (ugly) permalinks restores the expected
behavior. Also note that using the ?cat=1 style URL gives the expected
behavior even with pretty permalinks enabled.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/26627>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list