Ticket #16170: 16170.3.diff
File 16170.3.diff, 4.0 KB (added by , 14 years ago) |
---|
-
wp-includes/functions.php
3049 3049 * 3050 3050 * @param array $list An array of objects to filter 3051 3051 * @param array $args An array of key => value arguments to match against each object 3052 * @param string $operator The logical operation to perform. 'or' means only one element 3053 * from the array needs to match; 'and' means all elements must match. The default is 'and'. 3052 * @param string $operator The logical operation to perform: 3053 * 'AND' means all elements from the array must match; 3054 * 'OR' means only one element needs to match; 3055 * 'NOT' means no elements may match. 3056 * The default is 'AND'. 3054 3057 * @return array 3055 3058 */ 3056 function wp_list_filter( $list, $args = array(), $operator = ' and' ) {3059 function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { 3057 3060 if ( empty( $args ) ) 3058 3061 return $list; 3059 3062 3063 $operator = strtoupper( $operator ); 3060 3064 $count = count( $args ); 3061 3062 3065 $filtered = array(); 3063 3066 3064 3067 foreach ( $list as $key => $obj ) { 3065 3068 $matched = count( array_intersect_assoc( (array) $obj, $args ) ); 3066 if ( ('and' == $operator && $matched == $count) || ('or' == $operator && $matched <= $count) ) { 3069 if ( ( 'AND' == $operator && $matched == $count ) 3070 || ( 'OR' == $operator && $matched <= $count ) 3071 || ( 'NOT' == $operator && 0 == $matched ) ) { 3067 3072 $filtered[$key] = $obj; 3068 3073 } 3069 3074 } -
wp-includes/query.php
2143 2143 2144 2144 // Back-compat 2145 2145 if ( !empty($this->tax_query->queries) ) { 2146 $tax_query_in = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'IN' ));2147 if ( !empty( $tax_query_in ) ) {2146 $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); 2147 if ( !empty( $tax_query_in_and ) ) { 2148 2148 if ( !isset( $q['taxonomy'] ) ) { 2149 foreach ( $tax_query_in as $a_tax_query ) {2149 foreach ( $tax_query_in_and as $a_tax_query ) { 2150 2150 if ( !in_array( $a_tax_query['taxonomy'], array( 'category', 'post_tag' ) ) ) { 2151 2151 $q['taxonomy'] = $a_tax_query['taxonomy']; 2152 2152 if ( 'slug' == $a_tax_query['field'] ) … … 2159 2159 } 2160 2160 } 2161 2161 2162 $cat_query = wp_list_filter( $tax_query_in , array( 'taxonomy' => 'category' ) );2162 $cat_query = wp_list_filter( $tax_query_in_and, array( 'taxonomy' => 'category' ) ); 2163 2163 if ( !empty( $cat_query ) ) { 2164 2164 $cat_query = reset( $cat_query ); 2165 $ cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' );2166 if ( $ cat ) {2167 $this->set( 'cat', $ cat->term_id );2168 $this->set( 'category_name', $ cat->slug );2165 $the_cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); 2166 if ( $the_cat ) { 2167 $this->set( 'cat', $the_cat->term_id ); 2168 $this->set( 'category_name', $the_cat->slug ); 2169 2169 } 2170 unset( $the_cat ); 2170 2171 } 2172 unset( $cat_query ); 2173 2174 $tag_query = wp_list_filter( $tax_query_in_and, array( 'taxonomy' => 'post_tag' ) ); 2175 if ( !empty( $tag_query ) ) { 2176 $tag_query = reset( $tag_query ); 2177 $the_tag = get_term_by( $tag_query['field'], $tag_query['terms'][0], 'post_tag' ); 2178 if ( $the_tag ) { 2179 $this->set( 'tag_id', $the_tag->term_id ); 2180 } 2181 unset( $the_tag ); 2182 } 2183 unset( $tag_query ); 2171 2184 } 2172 2185 } 2173 2186 … … 2844 2857 $this->queried_object_id = 0; 2845 2858 2846 2859 if ( $this->is_category || $this->is_tag || $this->is_tax ) { 2847 $tax_query_in = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'IN' ));2860 $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); 2848 2861 2849 $query = reset( $tax_query_in );2862 $query = reset( $tax_query_in_and ); 2850 2863 2851 2864 if ( 'term_id' == $query['field'] ) 2852 2865 $term = get_term( reset( $query['terms'] ), $query['taxonomy'] );