Make WordPress Core

Ticket #28439: 28439.2.patch

File 28439.2.patch, 1.1 KB (added by jchristopher, 10 years ago)

To prevent duplicate terms, SELECT DISTINCT when orderby = 'post_date'

  • wp-includes/taxonomy.php

     
    13851385                $orderby = 't.slug';
    13861386        } else if ( 'term_group' == $_orderby ) {
    13871387                $orderby = 't.term_group';
     1388        } else if ( 'post_date' == $_orderby ) {
     1389                $orderby = 'p.post_date';
    13881390        } else if ( 'none' == $_orderby ) {
    13891391                $orderby = '';
    13901392        } elseif ( empty($_orderby) || 'id' == $_orderby ) {
     
    15611563
    15621564        $join = "INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id";
    15631565
     1566        // if we're ordering by date, we need to SELECT DISTINCT and JOIN term_relationships and posts
     1567        if ( 'post_date' == $_orderby ) {
     1568                $fields = "DISTINCT " . $fields;
     1569                // JOIN with wp_term_relationships
     1570                $join .= " JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id";
     1571                // JOIN with wp_posts
     1572                $join .= " JOIN $wpdb->posts AS p ON p.ID = tr.object_id";
     1573        }
     1574
    15641575        $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' );
    15651576
    15661577        /**