Changeset 31270
- Timestamp:
- 01/23/2015 02:56:04 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r31248 r31270 2556 2556 * @since 2.3.0 2557 2557 * @since 4.2.0 Added support for 'taxonomy', 'parent', and 'term_taxonomy_id' values of `$orderby`. 2558 * Introduced `$parent` parameter. 2558 2559 * 2559 2560 * @global wpdb $wpdb WordPress database abstraction object. … … 2570 2571 * term objects being returned, 'ids' will return an array of integers, and 'names' an array 2571 2572 * of strings. 2573 * @type int $parent Optional. Limit results to the direct children of a given term ID. 2572 2574 * } 2573 2575 * @return array|WP_Error The requested term data or empty array if no terms found. … … 2592 2594 $object_ids = array_map('intval', $object_ids); 2593 2595 2594 $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'); 2596 $defaults = array( 2597 'orderby' => 'name', 2598 'order' => 'ASC', 2599 'fields' => 'all', 2600 'parent' => '', 2601 ); 2595 2602 $args = wp_parse_args( $args, $defaults ); 2596 2603 … … 2653 2660 $select_this = 't.*, tt.*, tr.object_id'; 2654 2661 } 2655 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order"; 2662 2663 $where = array( 2664 "tt.taxonomy IN ($taxonomies)", 2665 "tr.object_id IN ($object_ids)", 2666 ); 2667 2668 if ( '' !== $args['parent'] ) { 2669 $where[] = $wpdb->prepare( 'tt.parent = %d', $args['parent'] ); 2670 } 2671 2672 $where = implode( ' AND ', $where ); 2673 2674 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE $where $orderby $order"; 2656 2675 2657 2676 $objects = false; -
trunk/tests/phpunit/tests/term/wpGetObjectTerms.php
r31236 r31270 357 357 } 358 358 359 /** 360 * @ticket 15675 361 */ 362 public function test_parent() { 363 $t1 = $this->factory->term->create( array( 364 'taxonomy' => $this->taxonomy, 365 ) ); 366 $t2 = $this->factory->term->create( array( 367 'taxonomy' => $this->taxonomy, 368 ) ); 369 $t3 = $this->factory->term->create( array( 370 'taxonomy' => $this->taxonomy, 371 'parent' => $t1, 372 ) ); 373 $t4 = $this->factory->term->create( array( 374 'taxonomy' => $this->taxonomy, 375 'parent' => $t2, 376 ) ); 377 378 $p = $this->factory->post->create(); 379 380 wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), $this->taxonomy ); 381 382 $found = wp_get_object_terms( $p, $this->taxonomy, array( 383 'parent' => $t1, 384 'fields' => 'ids', 385 ) ); 386 387 $this->assertEquals( array( $t3 ), $found ); 388 } 389 390 /** 391 * @ticket 15675 392 */ 393 public function test_parent_0() { 394 $t1 = $this->factory->term->create( array( 395 'taxonomy' => $this->taxonomy, 396 ) ); 397 $t2 = $this->factory->term->create( array( 398 'taxonomy' => $this->taxonomy, 399 ) ); 400 $t3 = $this->factory->term->create( array( 401 'taxonomy' => $this->taxonomy, 402 'parent' => $t1, 403 ) ); 404 $t4 = $this->factory->term->create( array( 405 'taxonomy' => $this->taxonomy, 406 'parent' => $t2, 407 ) ); 408 409 $p = $this->factory->post->create(); 410 411 wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), $this->taxonomy ); 412 413 $found = wp_get_object_terms( $p, $this->taxonomy, array( 414 'parent' => 0, 415 'fields' => 'ids', 416 ) ); 417 418 $this->assertEqualSets( array( $t1, $t2 ), $found ); 419 } 420 359 421 public function filter_get_object_terms( $terms ) { 360 422 $term_ids = wp_list_pluck( $terms, 'term_id' );
Note: See TracChangeset
for help on using the changeset viewer.