WordPress.org

Make WordPress Core

Changeset 30026


Ignore:
Timestamp:
10/26/14 16:45:37 (4 days ago)
Author:
boonebgorges
Message:

Fix 'count' in WP_Comment_Query when using 'meta_query'.

Props heshiming, desaiuditd.
Fixes #23369.

Location:
trunk
Files:
2 edited

Legend:

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

    r30004 r30026  
    560560            $join .= $clauses['join']; 
    561561            $where .= $clauses['where']; 
    562             $groupby = "{$wpdb->comments}.comment_ID"; 
     562 
     563            if ( ! $this->query_vars['count'] ) { 
     564                $groupby = "{$wpdb->comments}.comment_ID"; 
     565            } 
    563566        } 
    564567 
  • trunk/tests/phpunit/tests/comment/query.php

    r30004 r30026  
    614614        $this->assertNotContains( 'ORDER BY', $q->request ); 
    615615    } 
     616 
     617    public function test_count() { 
     618        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) ); 
     619        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) ); 
     620 
     621        $q = new WP_Comment_Query(); 
     622        $found = $q->query( array( 
     623            'count' => true, 
     624        ) ); 
     625 
     626        $this->assertEquals( 2, $found ); 
     627    } 
     628 
     629    /** 
     630     * @ticket 23369 
     631     */ 
     632    public function test_count_with_meta_query() { 
     633        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) ); 
     634        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) ); 
     635        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) ); 
     636        add_comment_meta( $c1, 'foo', 'bar' ); 
     637        add_comment_meta( $c3, 'foo', 'bar' ); 
     638 
     639        $q = new WP_Comment_Query(); 
     640        $found = $q->query( array( 
     641            'count' => true, 
     642            'meta_query' => array( 
     643                array( 
     644                    'key' => 'foo', 
     645                    'value' => 'bar', 
     646                ), 
     647            ), 
     648        ) ); 
     649 
     650        $this->assertEquals( 2, $found ); 
     651    } 
    616652} 
Note: See TracChangeset for help on using the changeset viewer.