*/
function wp_reset_postdata() {
global $wp_query;
- $wp_query->reset_postdata();
+
+ if ( isset( $wp_query ) ) {
+ $wp_query->reset_postdata();
+ }
}
/*
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 ) ) {