Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#8087 closed defect (bug) (fixed)

get_terms problems

Reported by: filosofo's profile filosofo Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.7
Component: General Keywords: has-patch get_terms taxonomy children _get_term_children
Focuses: Cc:


There are a couple of problems with get_terms:

  • If the 'child_of' argument is 0 and 'hierarchical' is true (the defaults), then terms that have non-zero parent terms are disregarded, thanks to the following line: $terms = & _get_term_children($child_of, $terms, $taxonomies[0]);

Because $child_of == 0 and such terms have a non-zero parent, _get_term_children excludes them.

  • get_terms allows you to select fields "ids" or "names," in which case it currently uses $wpdb->get_col to get an array of those values. However, later get_terms attempts to count child terms (if appropriate) and weed out empty terms (if appropriate). But it fails to do so in the case when 'fields' is set to 'ids' or 'names'.

My patch fixes these issues. It gets term objects from the database no matter what, so the results are consistent no matter what fields are requested, and _get_term_children is more efficient, because it's not retrieving object info for every term.

I've also made the phpdoc descriptions a little more helpful.

Attachments (1)

get_terms.diff (7.2 KB) - added by filosofo 15 years ago.

Download all attachments as: .zip

Change History (2)

15 years ago

#1 @ryan
15 years ago

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

(In [9652]) get_terms() improvements from filosofo. fixes #8087

Note: See TracTickets for help on using tickets.