| | 1192 | * @ticket 27272 |
| | 1193 | */ |
| | 1194 | public function test_meta_query_cast_value_signed() { |
| | 1195 | $posts = $this->factory->post->create_many( 3 ); |
| | 1196 | update_post_meta( $posts[0], 'foo', '2' ); |
| | 1197 | update_post_meta( $posts[1], 'foo', '101' ); |
| | 1198 | |
| | 1199 | $q = new WP_Query( array( |
| | 1200 | 'update_post_meta_cache' => false, |
| | 1201 | 'update_term_meta_cache' => false, |
| | 1202 | 'fields' => 'ids', |
| | 1203 | 'meta_query' => array( |
| | 1204 | array( |
| | 1205 | 'key' => 'foo', |
| | 1206 | 'value' => '10', |
| | 1207 | 'compare' => '>=', |
| | 1208 | 'type' => 'SIGNED', |
| | 1209 | ), |
| | 1210 | ), |
| | 1211 | ) ); |
| | 1212 | |
| | 1213 | $this->assertEquals( array( $posts[1] ), $q->posts ); |
| | 1214 | } |
| | 1215 | |
| | 1216 | /** |
| | 1217 | * @group meta |
| | 1218 | * @ticket 27272 |
| | 1219 | */ |
| | 1220 | public function test_meta_query_cast_value_numeric() { |
| | 1221 | $posts = $this->factory->post->create_many( 3 ); |
| | 1222 | update_post_meta( $posts[0], 'foo', '2' ); |
| | 1223 | update_post_meta( $posts[1], 'foo', '101' ); |
| | 1224 | |
| | 1225 | $q = new WP_Query( array( |
| | 1226 | 'update_post_meta_cache' => false, |
| | 1227 | 'update_term_meta_cache' => false, |
| | 1228 | 'fields' => 'ids', |
| | 1229 | 'meta_query' => array( |
| | 1230 | array( |
| | 1231 | 'key' => 'foo', |
| | 1232 | 'value' => '10', |
| | 1233 | 'compare' => '>=', |
| | 1234 | 'type' => 'NUMERIC', |
| | 1235 | ), |
| | 1236 | ), |
| | 1237 | ) ); |
| | 1238 | |
| | 1239 | $this->assertEquals( array( $posts[1] ), $q->posts ); |
| | 1240 | } |
| | 1241 | |
| | 1242 | /** |
| | 1243 | * @group meta |
| | 1244 | * @ticket 27272 |
| | 1245 | */ |
| | 1246 | public function test_meta_query_cast_value_datetime() { |
| | 1247 | $posts = $this->factory->post->create_many( 3 ); |
| | 1248 | update_post_meta( $posts[0], 'foo', '2013' ); |
| | 1249 | update_post_meta( $posts[1], 'foo', '2013-05-05 00:00:00' ); |
| | 1250 | |
| | 1251 | $q = new WP_Query( array( |
| | 1252 | 'update_post_meta_cache' => false, |
| | 1253 | 'update_term_meta_cache' => false, |
| | 1254 | 'fields' => 'ids', |
| | 1255 | 'meta_query' => array( |
| | 1256 | array( |
| | 1257 | 'key' => 'foo', |
| | 1258 | 'value' => '2012-12-01 00:00:00', |
| | 1259 | 'compare' => '>=', |
| | 1260 | 'type' => 'DATETIME', |
| | 1261 | ), |
| | 1262 | ), |
| | 1263 | ) ); |
| | 1264 | |
| | 1265 | $this->assertEquals( array( $posts[1] ), $q->posts ); |
| | 1266 | } |
| | 1267 | |
| | 1268 | /** |
| | 1269 | * @group meta |