[wp-trac] [WordPress Trac] #10907: get_queried_object does not always return a category

WordPress Trac wp-trac at lists.automattic.com
Mon Oct 5 16:35:38 UTC 2009


#10907: get_queried_object does not always return a category
--------------------------+-------------------------------------------------
 Reporter:  dimitryz      |       Owner:  ryan                        
     Type:  defect (bug)  |      Status:  new                         
 Priority:  normal        |   Milestone:  Unassigned                  
Component:  Query         |     Version:  2.8.4                       
 Severity:  normal        |    Keywords:  get_queried_object, category
--------------------------+-------------------------------------------------
 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;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10907>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list