| 203 | * @ticket boone |
| 204 | */ |
| 205 | function test_meta_query_multiple_clauses_with_compare_equals() { |
| 206 | $p1 = $this->factory->post->create(); |
| 207 | add_post_meta( $p1, 'foo', 'foovalue' ); |
| 208 | $p2 = $this->factory->post->create(); |
| 209 | add_post_meta( $p2, 'bar', 'barvalue' ); |
| 210 | $p3 = $this->factory->post->create(); |
| 211 | add_post_meta( $p3, 'bar', 'barvalue2' ); |
| 212 | $p4 = $this->factory->post->create(); |
| 213 | add_post_meta( $p4, 'baz', 'bazvalue' ); |
| 214 | $p5 = $this->factory->post->create(); |
| 215 | add_post_meta( $p5, 'foo', 'foovalue2' ); |
| 216 | |
| 217 | $query = new WP_Query( array( |
| 218 | 'meta_query' => array( |
| 219 | 'relation' => 'OR', |
| 220 | array( |
| 221 | 'key' => 'foo', |
| 222 | 'value' => 'foovalue2', |
| 223 | 'compare' => '=', |
| 224 | ), |
| 225 | array( |
| 226 | 'key' => 'bar', |
| 227 | 'value' => 'barvalue2', |
| 228 | 'compare' => '=', |
| 229 | ), |
| 230 | ), |
| 231 | ) ); |
| 232 | |
| 233 | $posts = $query->get_posts(); |
| 234 | |
| 235 | $this->assertEqualSets( array( $p5, $p3 ), wp_list_pluck( $posts, 'ID' ) ); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * @ticket boone |
| 240 | */ |
| 241 | function test_meta_query_multiple_clauses_with_compare_not_equals() { |
| 242 | $p1 = $this->factory->post->create(); |
| 243 | add_post_meta( $p1, 'foo', 'foovalue' ); |
| 244 | $p2 = $this->factory->post->create(); |
| 245 | add_post_meta( $p2, 'bar', 'barvalue' ); |
| 246 | $p3 = $this->factory->post->create(); |
| 247 | add_post_meta( $p3, 'bar', 'barvalue2' ); |
| 248 | $p4 = $this->factory->post->create(); |
| 249 | add_post_meta( $p4, 'baz', 'bazvalue' ); |
| 250 | $p5 = $this->factory->post->create(); |
| 251 | add_post_meta( $p5, 'foo', 'foovalue2' ); |
| 252 | |
| 253 | $query = new WP_Query( array( |
| 254 | 'meta_query' => array( |
| 255 | 'relation' => 'AND', |
| 256 | array( |
| 257 | 'key' => 'foo', |
| 258 | 'value' => 'foovalue2', |
| 259 | 'compare' => '!=', |
| 260 | ), |
| 261 | array( |
| 262 | 'key' => 'bar', |
| 263 | 'value' => 'barvalue2', |
| 264 | 'compare' => '!=', |
| 265 | ), |
| 266 | ), |
| 267 | ) ); |
| 268 | |
| 269 | $posts = $query->get_posts(); |
| 270 | |
| 271 | $this->assertEqualSets( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) ); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * @ticket boone |
| 276 | */ |
| 277 | function test_meta_query_multiple_clauses_with_compare_greater_than() { |
| 278 | $p1 = $this->factory->post->create(); |
| 279 | add_post_meta( $p1, 'foo', '1' ); |
| 280 | $p2 = $this->factory->post->create(); |
| 281 | add_post_meta( $p2, 'bar', '2' ); |
| 282 | $p3 = $this->factory->post->create(); |
| 283 | add_post_meta( $p3, 'bar', '3' ); |
| 284 | $p4 = $this->factory->post->create(); |
| 285 | add_post_meta( $p4, 'baz', '4' ); |
| 286 | $p5 = $this->factory->post->create(); |
| 287 | add_post_meta( $p5, 'foo', '5' ); |
| 288 | |
| 289 | $query = new WP_Query( array( |
| 290 | 'meta_query' => array( |
| 291 | 'relation' => 'OR', |
| 292 | array( |
| 293 | 'key' => 'foo', |
| 294 | 'value' => '1', |
| 295 | 'compare' => '>', |
| 296 | ), |
| 297 | array( |
| 298 | 'key' => 'bar', |
| 299 | 'value' => '2', |
| 300 | 'compare' => '>', |
| 301 | ), |
| 302 | ), |
| 303 | ) ); |
| 304 | |
| 305 | $posts = $query->get_posts(); |
| 306 | |
| 307 | $this->assertEqualSets( array( $p3, $p5 ), wp_list_pluck( $posts, 'ID' ) ); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * @ticket boone |
| 312 | */ |
| 313 | function test_meta_query_multiple_clauses_with_compare_like() { |
| 314 | $p1 = $this->factory->post->create(); |
| 315 | add_post_meta( $p1, 'foo', 'abcde' ); |
| 316 | $p2 = $this->factory->post->create(); |
| 317 | add_post_meta( $p2, 'bar', 'aaaabcdeee' ); |
| 318 | $p3 = $this->factory->post->create(); |
| 319 | add_post_meta( $p3, 'bar', 'fghij' ); |
| 320 | $p4 = $this->factory->post->create(); |
| 321 | add_post_meta( $p4, 'baz', 'fffghijjjj' ); |
| 322 | $p5 = $this->factory->post->create(); |
| 323 | add_post_meta( $p5, 'foo', 'aaaabcdeeee' ); |
| 324 | |
| 325 | $query = new WP_Query( array( |
| 326 | 'meta_query' => array( |
| 327 | 'relation' => 'OR', |
| 328 | array( |
| 329 | 'key' => 'foo', |
| 330 | 'value' => 'aaa', |
| 331 | 'compare' => 'LIKE', |
| 332 | ), |
| 333 | array( |
| 334 | 'key' => 'bar', |
| 335 | 'value' => 'bc', |
| 336 | 'compare' => 'LIKE', |
| 337 | ), |
| 338 | ), |
| 339 | ) ); |
| 340 | |
| 341 | $posts = $query->get_posts(); |
| 342 | |
| 343 | $this->assertEqualSets( array( $p5, $p2 ), wp_list_pluck( $posts, 'ID' ) ); |
| 344 | } |
| 345 | |
| 346 | /** |