| | 297 | function test_query_post_parent__in() { |
| | 298 | $parent_id = $this->factory->post->create( array( 'post_title' => 'parent-post' ) ); |
| | 299 | $child_id = $this->factory->post->create( array( 'post_title' => 'child-post', 'post_parent' => $parent_id ) ); |
| | 300 | |
| | 301 | $posts = $this->q->query( array( |
| | 302 | 'fields' => 'ids', |
| | 303 | 'post_parent__in' => array( $parent_id ) |
| | 304 | ) ); |
| | 305 | |
| | 306 | $this->assertEquals( reset( $posts ), $child_id ); |
| | 307 | } |
| | 308 | |
| | 309 | function test_order_post_parent__in() { |
| | 310 | $parent_id1 = $this->factory->post->create( array( 'post_title' => rand_str() ) ); |
| | 311 | $parent_id2 = $this->factory->post->create( array( 'post_title' => rand_str() ) ); |
| | 312 | $this->factory->post->create( array( 'post_title' => rand_str(), 'post_parent' => $parent_id2 ) ); |
| | 313 | $this->factory->post->create( array( 'post_title' => rand_str(), 'post_parent' => $parent_id1 ) ); |
| | 314 | $this->factory->post->create( array( 'post_title' => rand_str(), 'post_parent' => $parent_id2 ) ); |
| | 315 | $this->factory->post->create( array( 'post_title' => rand_str(), 'post_parent' => $parent_id1 ) ); |
| | 316 | |
| | 317 | $posts = $this->q->query( array( |
| | 318 | 'fields' => 'id=>parent', |
| | 319 | 'post_parent__in' => array( $parent_id1, $parent_id2 ), |
| | 320 | 'orderby' => 'post_parent__in', |
| | 321 | 'order' => 'ASC' |
| | 322 | ) ); |
| | 323 | |
| | 324 | $values = array_map( 'absint', array_values( $posts ) ); |
| | 325 | $parents = $values; |
| | 326 | sort( $parents ); |
| | 327 | $this->assertEquals( $parents, $values ); |
| | 328 | } |