WordPress.org

Make WordPress Core

Changeset 25238


Ignore:
Timestamp:
09/04/2013 06:16:31 PM (8 years ago)
Author:
wonderboymusic
Message:

Convert category__and to category__in (less expensive) and unset it when only one category is passed. Adds unit tests.

Fixes #24245.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r25139 r25238  
    17631763        }
    17641764
    1765         if ( !empty($q['category__in']) ) {
    1766             $q['category__in'] = array_map('absint', array_unique( (array) $q['category__in'] ) );
     1765        if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) {
     1766            $q['category__and'] = (array) $q['category__and'];
     1767            if ( ! isset( $q['category__in'] ) )
     1768                $q['category__in'] = array();
     1769            $q['category__in'][] = absint( reset( $q['category__and'] ) );
     1770            unset( $q['category__and'] );
     1771        }
     1772           
     1773        if ( ! empty( $q['category__in'] ) ) {
     1774            $q['category__in'] = array_map( 'absint', array_unique( (array) $q['category__in'] ) );         
    17671775            $tax_query[] = array(
    17681776                'taxonomy' => 'category',
     
    17731781        }
    17741782
    1775         if ( !empty($q['category__not_in']) ) {
    1776             $q['category__not_in'] = array_map('absint', array_unique( (array) $q['category__not_in'] ) );
     1783        if ( ! empty($q['category__not_in']) ) {
     1784            $q['category__not_in'] = array_map( 'absint', array_unique( (array) $q['category__not_in'] ) );
    17771785            $tax_query[] = array(
    17781786                'taxonomy' => 'category',
     
    17831791        }
    17841792
    1785         if ( !empty($q['category__and']) ) {
    1786             $q['category__and'] = array_map('absint', array_unique( (array) $q['category__and'] ) );
     1793        if ( ! empty($q['category__and']) ) {
     1794            $q['category__and'] = array_map( 'absint', array_unique( (array) $q['category__and'] ) );
    17871795            $tax_query[] = array(
    17881796                'taxonomy' => 'category',
Note: See TracChangeset for help on using the changeset viewer.