modified the function to get selected categories for filtering