]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/query.php
WordPress 3.8.2
[autoinstalls/wordpress.git] / wp-includes / query.php
index 1ec9566c41166c967569a085449487e8a2a83708..446cebca0d83de1d140e87bed534c72e92b28651 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,28 @@ 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' );
+                               if ( $this->get( 'tag_id' ) ) {
+                                       $term = get_term( $this->get( 'tag_id' ), 'post_tag' );
+                               } elseif ( $this->get( 'tag' ) ) {
+                                       $term = get_term_by( 'slug', $this->get( 'tag' ), '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 ) )  {