Get customer by custom attribute in Magento
Posted by navaneeth on May 27, 2015 in General, Magento, Php | No comments yet
![Get customer by custom attribute in Magento](https://i0.wp.com/navaneeth.me/wp-content/uploads/2015/05/get-customer-custom-attribute-in-magento.jpg?fit=584%2C241&ssl=1)
We can get customer by custom attribute in magento with a single line of code as shown below, Just pass the attribute name and the desired value
<?php $customer=Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('username', 'yourusernamehere')->load(); ?>
In the above code username is the desired custom attribute
and yourusernamehere is the value of the custom attribute
in $customer the customers matching the criteria will get as an array
hope this helps you to get customer by custom attribute in magento
Leave a Reply