Opened 18 years ago
Closed 18 years ago
#5780 closed defect (bug) (fixed)
get_terms returns empty array for parameter fields=names
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 2.5 | Priority: | normal |
| Severity: | normal | Version: | 2.3.2 |
| Component: | General | Keywords: | has-patch |
| Focuses: | Cc: |
Description
The function call
get_terms('post_tag', 'fields=names')
is expected to return an array containing all tag names. An empty array is returned instead.
get_terms('post_tag', 'fields=ids')
returns an array with all tag IDs as expected.
This error is the result of wrong operator and a missing if-condition in taxonomy.php:
Current code (starting from line 572:
else if ( 'names' == $fields )
$select_this == 't.name';
$query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number";
if ( 'all' == $fields ) {
$terms = $wpdb->get_results($query);
update_term_cache($terms);
} else if ( 'ids' == $fields ) {
$terms = $wpdb->get_col($query);
}
Fixed code:
else if ( 'names' == $fields )
$select_this = 't.name';
$query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $number";
if ( 'all' == $fields ) {
$terms = $wpdb->get_results($query);
update_term_cache($terms);
} else if ( ('ids' == $fields) || ('names' == $fields) ) {
$terms = $wpdb->get_col($query);
}
Attachments (1)
Change History (4)
Note: See
TracTickets for help on using
tickets.
Patch file for ticket #5780