fixes #5498 Error adding categories to a content

Fixed the issue and pushed the code for review, please check it.