Opened 16 years ago
Closed 16 years ago
#10907 closed defect (bug) (worksforme)
get_queried_object does not always return a category
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 2.8.4 |
| Component: | Query | Keywords: | reporter-feedback |
| Focuses: | Cc: |
Description
I've noticed that retrieving a category with WP_Query::get_queried_object() does not always work. When the query_var 'cat' is not set and 'category_name' is, nothing is returned. Shouldn't get_queried_object() also look in 'category_name' and, if present, retrieve the category using get_category_by_path()?
Here is a solution that seems appropriate:
function get_queried_object() {
...
if ($this->is_category) {
$cat = $this->get('cat');
if ($cat) {
$category = &get_category($cat);
} else {
$cat = $this->get('category_name');
$category = &get_category_by_path($cat);
}
if ( is_wp_error( $category ) )
return NULL;
$this->queried_object = &$category;
$this->queried_object_id = (int) $category->term_id;
}
Change History (3)
Note: See
TracTickets for help on using
tickets.
What sort of query are you using to cause this? Is it a specific URL?
for requests serving 'category_name', 'cat' should be set, as its already run through get_category_by_path by this code: http://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L1877