cat_row doesn't not list all categories
|Reported by:||hailin||Owned by:||anonymous|
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)
- Resolution set to invalid
- Status changed from new to closed
- Keywords developer-feedback added; reporter-feedback removed
- 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