Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#5780 closed defect (bug) (fixed)

get_terms returns empty array for parameter fields=names

Reported by: sarky-de's profile Sarky-de Owned by: ryan's profile ryan
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)

5780.diff (771 bytes) - added by Sarky-de 17 years ago.
Patch file for ticket #5780

Download all attachments as: .zip

Change History (4)

@Sarky-de
17 years ago

Patch file for ticket #5780

#1 @ryan
17 years ago

  • Owner changed from anonymous to ryan

#2 @lloydbudd
17 years ago

  • Milestone changed from 2.6 to 2.5

#3 @ryan
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [6738]) Fix fields=names query in get_terms(). Props Sarky-de. fixes #5780

Note: See TracTickets for help on using tickets.