WordPress 3.8.1
[autoinstalls/wordpress.git] / wp-includes / query.php
index 1ec9566c41166c967569a085449487e8a2a83708..8bf292e1fe4b9412b5e28539d49d069d37c8b30b 100644 (file)
@@ -115,7 +115,10 @@ function wp_reset_query() {
  */
 function wp_reset_postdata() {
        global $wp_query;
-       $wp_query->reset_postdata();
+
+       if ( isset( $wp_query ) ) {
+               $wp_query->reset_postdata();
+       }
 }
 
 /*
@@ -3264,17 +3267,24 @@ class WP_Query {
 
                if ( $this->is_category || $this->is_tag || $this->is_tax ) {
                        if ( $this->is_category ) {
-                               $term = get_term( $this->get( 'cat' ), 'category' );
+                               if ( $this->get( 'cat' ) ) {
+                                       $term = get_term( $this->get( 'cat' ), 'category' );
+                               } elseif ( $this->get( 'category_name' ) ) {
+                                       $term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' );
+                               }
                        } elseif ( $this->is_tag ) {
                                $term = get_term( $this->get( 'tag_id' ), 'post_tag' );
                        } else {
                                $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
                                $query = reset( $tax_query_in_and );
 
-                               if ( 'term_id' == $query['field'] )
-                                       $term = get_term( reset( $query['terms'] ), $query['taxonomy'] );
-                               else
-                                       $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );
+                               if ( $query['terms'] ) {
+                                       if ( 'term_id' == $query['field'] ) {
+                                               $term = get_term( reset( $query['terms'] ), $query['taxonomy'] );
+                                       } else {
+                                               $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );
+                                       }
+                               }
                        }
 
                        if ( ! empty( $term ) && ! is_wp_error( $term ) )  {