Skip to content

How to filter customer collection by custom field added by db_schema xml file to customer_entity table in Magento 2?

I added ‘custom_field’ to ‘customer_entity’ table by using ‘db_schema.xml’ file and need to save ‘some value’ in it then I wanted to filter the collection by ‘custom_field’ value. How can I achieve this ? When I use the below code.

$customer = $this->_customerFactory->create();
$customerData = $customer->getCollection()->addAttributeToFilter('custom_field',array('neq'=>'cleared'))->setOrder('entity_id','ASC')->load();

I am getting this error : The "custom_field" attribute name is invalid. Reset the name and try again.