I need to get customer id before login by custom attribute value in Magento 2.1.5, for login by username.


1 Answer 1


Please Try below code :

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customerObj = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection');
    $collection = $customerObj->addAttributeToSelect('*')
   echo $c_data[0]['entity_id']; 
  • @Bapu I have updated my answer please check. May 1, 2017 at 9:13
  • Thanx deexit & manthan too May 1, 2017 at 9:36
  • Before login it secure or not? May 1, 2017 at 9:37
  • How we can get customer attribute collection in magento 2? Because i want to show on catalog price rule form. How i can achieve this? Aug 3, 2017 at 7:03
  • It always displays first record...seems it holds first record. Aug 6, 2020 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.