Fixed DB error on view page

Fixed DB error when sorting and filtering by custom fields