Ticket #5780 (closed defect: fixed)

Opened 10 months ago

Last modified 10 months ago

get_terms returns empty array for parameter fields=names

Reported by: Sarky-de Assigned to: ryan
Priority: normal Milestone: 2.5
Component: General Version: 2.3.2
Severity: normal Keywords: has-patch
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

5780.diff (0.8 kB) - added by Sarky-de on 02/06/08 17:20:50.
Patch file for ticket #5780

Change History

02/06/08 17:20:50 changed by Sarky-de

  • attachment 5780.diff added.

Patch file for ticket #5780

02/06/08 18:46:17 changed by ryan

  • owner changed from anonymous to ryan.

02/06/08 18:59:43 changed by lloydbudd

  • milestone changed from 2.6 to 2.5.

02/06/08 20:42:03 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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