mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
When meta_type is passed with orderby => meta_value, orderby must also use CAST() to avoid scenarios like: SELECTing by UNSIGNED and then ordering by CHAR. Adds unit test.
Fixes #21621. git-svn-id: https://develop.svn.wordpress.org/trunk@25255 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -150,4 +150,25 @@ class Tests_Meta extends WP_UnitTestCase {
|
||||
$this->assertInternalType( 'int', update_metadata( 'user', $this->author->ID, $key, $value2 ) );
|
||||
$this->assertEquals( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );
|
||||
}
|
||||
|
||||
function test_meta_type_cast() {
|
||||
$post_id1 = $this->factory->post->create();
|
||||
add_post_meta( $post_id1, 'num_as_longtext', 123 );
|
||||
$post_id2 = $this->factory->post->create();
|
||||
add_post_meta( $post_id2, 'num_as_longtext', 99 );
|
||||
|
||||
$posts = new WP_Query( array(
|
||||
'fields' => 'ids',
|
||||
'post_type' => 'any',
|
||||
'meta_key' => 'num_as_longtext',
|
||||
'meta_value' => '0',
|
||||
'meta_compare' => '>',
|
||||
'meta_type' => 'UNSIGNED',
|
||||
'orderby' => 'meta_value',
|
||||
'order' => 'ASC'
|
||||
) );
|
||||
|
||||
$this->assertEquals( array( $post_id2, $post_id1 ), $posts->posts );
|
||||
$this->assertEquals( 2, substr_count( $posts->request, 'CAST(' ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user