Changeset 25161
- Timestamp:
- 08/29/2013 03:18:08 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r25142 r25161 1384 1384 switch ( $fields ) { 1385 1385 case 'all': 1386 $selects = array( 't.*', 'tt.*');1386 $selects = array( 't.*', 'tt.*' ); 1387 1387 break; 1388 1388 case 'ids': 1389 1389 case 'id=>parent': 1390 $selects = array( 't.term_id', 'tt.parent', 'tt.count');1390 $selects = array( 't.term_id', 'tt.parent', 'tt.count' ); 1391 1391 break; 1392 1392 case 'names': 1393 $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name');1393 $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name' ); 1394 1394 break; 1395 1395 case 'count': 1396 1396 $orderby = ''; 1397 1397 $order = ''; 1398 $selects = array('COUNT(*)'); 1398 $selects = array( 'COUNT(*)' ); 1399 break; 1400 case 'id=>name': 1401 $selects = array( 't.term_id', 't.name' ); 1402 break; 1403 case 'id=>slug': 1404 $selects = array( 't.term_id', 't.slug' ); 1405 break; 1399 1406 } 1400 1407 … … 1455 1462 } 1456 1463 } 1457 reset 1464 reset( $terms ); 1458 1465 1459 1466 $_terms = array(); 1460 1467 if ( 'id=>parent' == $fields ) { 1461 while ( $term = array_shift( $terms) )1468 while ( $term = array_shift( $terms ) ) 1462 1469 $_terms[$term->term_id] = $term->parent; 1470 } elseif ( 'ids' == $fields ) { 1471 while ( $term = array_shift( $terms ) ) 1472 $_terms[] = $term->term_id; 1473 } elseif ( 'names' == $fields ) { 1474 while ( $term = array_shift( $terms ) ) 1475 $_terms[] = $term->name; 1476 } elseif ( 'id=>name' == $fields ) { 1477 while ( $term = array_shift( $terms ) ) 1478 $_terms[$term->term_id] = $term->name; 1479 } elseif ( 'id=>slug' == $fields ) { 1480 while ( $term = array_shift( $terms ) ) 1481 $_terms[$term->term_id] = $term->slug; 1482 } 1483 1484 if ( ! empty( $_terms ) ) 1463 1485 $terms = $_terms; 1464 } elseif ( 'ids' == $fields ) {1465 while ( $term = array_shift($terms) )1466 $_terms[] = $term->term_id;1467 $terms = $_terms;1468 } elseif ( 'names' == $fields ) {1469 while ( $term = array_shift($terms) )1470 $_terms[] = $term->name;1471 $terms = $_terms;1472 }1473 1486 1474 1487 if ( $number && is_array( $terms ) && count( $terms ) > $number ) … … 1477 1490 wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); 1478 1491 1479 $terms = apply_filters( 'get_terms', $terms, $taxonomies, $args);1492 $terms = apply_filters( 'get_terms', $terms, $taxonomies, $args ); 1480 1493 return $terms; 1481 1494 } -
trunk/tests/data
-
Property
svn:ignore
set to
.trac-ticket-cache.core.trac.wordpress.org
.trac-ticket-cache.unit-tests.trac.wordpress.org
-
Property
svn:ignore
set to
-
trunk/tests/tests/term/getTerms.php
r25002 r25161 88 88 $this->assertEquals( $term_id, $terms[0]->term_id ); 89 89 } 90 91 /** 92 * @ticket 13661 93 */ 94 function test_get_terms_fields() { 95 $term_id1 = $this->factory->tag->create( array( 'slug' => 'woo', 'name' => 'WOO!' ) ); 96 $term_id2 = $this->factory->tag->create( array( 'slug' => 'hoo', 'name' => 'HOO!', 'parent' => $term_id1 ) ); 97 98 $terms_id_parent = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'id=>parent' ) ); 99 $this->assertEquals( array( 100 $term_id1 => 0, 101 $term_id2 => $term_id1 102 ), $terms_id_parent ); 103 104 $terms_ids = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'ids' ) ); 105 $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms_ids ); 106 107 $terms_name = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'names' ) ); 108 $this->assertEqualSets( array( 'WOO!', 'HOO!' ), $terms_name ); 109 110 $terms_id_name = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'id=>name' ) ); 111 $this->assertEquals( array( 112 $term_id1 => 'WOO!', 113 $term_id2 => 'HOO!', 114 ), $terms_id_name ); 115 116 $terms_id_slug = get_terms( 'post_tag', array( 'hide_empty' => false, 'fields' => 'id=>slug' ) ); 117 $this->assertEquals( array( 118 $term_id1 => 'woo', 119 $term_id2 => 'hoo' 120 ), $terms_id_slug ); 121 } 90 122 }
Note: See TracChangeset
for help on using the changeset viewer.