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:
Scott Taylor
2013-09-05 16:56:36 +00:00
parent 16ef2c2e36
commit 83d1992d34
3 changed files with 52 additions and 7 deletions

View File

@@ -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(' ) );
}
}