cat_row doesn't not list all categories
|Reported by:||hailin||Owned by:|
cat_rows and _cat_rows are buggy - it can not list all legitimate categories. The key reason is that within loop
foreach ( $categories as $category )
unset($categories[$i]) Prune the working set
We can not unset an element while the foreach loop is traversing the array, because it causes the internal PHP cursor to jump ahead, leaving out valid elements. It's ok to unset an element as long as there is no outer loop performing on the array.
Also, we should not try to get categories and children inside _cat_rows, instead, it's better to pass them in once and only once.
If the page starts in a subtree, the original author forgot to assign $my_parent = get_category( $p ); so the subtree handling was not working at all.
Overall, before and after my fix, the time complexity is O(N2), so it's not efficient when # of categories reach 1000. However, I think reasonable range is at most a few hundreds. If speed becomes an issue, I suggest we use an O(N) algorithm, similar to that used in page_rows.
Change History (29)
comment:2 in reply to: ↑ description hakre — 5 years ago
- Resolution set to invalid
- Status changed from new to closed
comment:13 in reply to: ↑ 11 hakre — 5 years ago
- Keywords developer-feedback added; reporter-feedback removed
comment:14 hakre — 5 years ago
- Milestone changed from Unassigned to 2.8
- Resolution invalid deleted
- Status changed from closed to reopened
- Keywords dev-feedback added; developer-feedback reporter-feedback removed