Make WordPress Core

Changeset 25257


Ignore:
Timestamp:
09/05/2013 05:14:54 PM (11 years ago)
Author:
wonderboymusic
Message:

Avoid database error when include or exclude is not really a term_id. Adds more unit tests.

Props kovshenin.
Fixes #11823.

Location:
trunk
Files:
2 edited

Legend:

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

    r25241 r25257  
    13111311    }
    13121312
    1313     if ( ! empty( $inclusions ) )
     1313    if ( ! empty( $inclusions ) ) {
    13141314        $inclusions = ' AND t.term_id IN ( ' . $inclusions . ' )';
    1315     $where .= $inclusions;
     1315        $where .= $inclusions;
     1316    }
    13161317
    13171318    $exclusions = '';
     
    13401341
    13411342    $exclusions = apply_filters( 'list_terms_exclusions', $exclusions, $args );
    1342     $where .= $exclusions;
     1343
     1344    if ( ! empty( $exclusions ) )
     1345        $where .= $exclusions;
    13431346
    13441347    if ( !empty($slug) ) {
  • trunk/tests/phpunit/tests/term/getTerms.php

    r25241 r25257  
    122122
    123123    /**
    124      * @ti
    125      * cket 11823
     124     * @ticket 11823
    126125     */
    127126    function test_get_terms_include_exclude() {
     127        global $wpdb;
     128
    128129        $term_id1 = $this->factory->tag->create();
    129130        $term_id2 = $this->factory->tag->create();
     
    139140        ) );
    140141        $this->assertEquals( array(), wp_list_pluck( $exc_terms, 'term_id' ) );
     142
     143        // These should not generate query errors.
     144        get_terms( 'post_tag', array( 'exclude' => array( 0 ), 'hide_empty' => false ) );
     145        $this->assertEmpty( $wpdb->last_error );
     146
     147        get_terms( 'post_tag', array( 'exclude' => array( 'unexpected-string' ), 'hide_empty' => false ) );
     148        $this->assertEmpty( $wpdb->last_error );
     149
     150        get_terms( 'post_tag', array( 'include' => array( 'unexpected-string' ), 'hide_empty' => false ) );
     151        $this->assertEmpty( $wpdb->last_error );
    141152    }
    142153
Note: See TracChangeset for help on using the changeset viewer.