invalid foreach when no categories are present
slight modification
Merge pull request #1887 from sumobi/master

invalid foreach