## #8832 closed defect (bug) (fixed)

# function get_categories() doesn't work properly when using child_of and number parameters

Reported by: | jidm | Owned by: | ryan |
---|---|---|---|

Milestone: | 2.7.1 | Priority: | normal |

Severity: | normal | Version: | 2.7 |

Component: | Taxonomy | Keywords: | has-patch get_terms number child_of |

Focuses: | Cc: |

### Description

The function get_categories() does not behave as expected when combining parameters "child_of" and "number".

Instead of showing X children of category Y, they are doing the following logic:

Get X categories (children or not). Then look in this result for children of category Y and show them. So the total result can be 5 categories, 3 categories, or even none.

### Attachments (1)

### Change History (8)

###
#2
@

12 years ago

To explain a little better:

What happens currently is that get_terms sets its initial database query limit to the "number" parameter, if supplied, and queries the database. It then goes through the returned terms and prunes out ones that aren't children of X term, or are empty, etc., depending on the other parameters.

So the number of terms returned by get_terms ultimately does not reflect the number of terms matching the parameters limited by the "number" parameter; rather, it reflects the number of terms returned by the initial query, some of which might not match all the parameters and will therefore be pruned out later.

My patch ignores the "number" parameter for the initial database query in those cases in which it's possible that some terms will later be pruned: e.g. the ones I mention above: when getting child_of, parent, etc. It then applies it to the array of terms before get_terms returns it.

**Note:**See TracTickets for help on using tickets.

Patch ignores number for the initial query whenever descending the taxonomy family tree is called for (when child_of is non-zero, parent is an integer, or hierarchical is true. It does a final terms count limiting at the end.