Check that categories is array before looping through. #1919