How to get order id from collection with filter customer_is_guest = 1 and customer email

$order_collection = $objectManager->create('Magento\Sales\Model\Order')->getCollection()->addAttributeToFilter('customer_email', $customer_email)->addAttributeToFilter('customer_is_guest',1);

Above code will give me order collection. How to only get order id/ids

  • Try $order_collection = $objectManager->create('Magento\Sales\Model\Order')->getCollection()->addAttributeToFilter('customer_id', array('eq' => NULL)) For guest customer you need to check customer_id is NULL
    – user55548
    Feb 15, 2019 at 10:00

2 Answers 2


You can use addFieldToSelect() function in your collection as follows:

$order_collection = $objectManager->create('Magento\Sales\Model\Order')->getCollection()
    ->addAttributeToFilter('customer_email', $customer_email)

Try this,

To get guest user orders by specific email

 namespace Vendor\Module\Controller\Orders;                               
 class ReadOrders extends \Magento\Framework\App\Action\Action {
 public function __construct(\Magento\Framework\App\Action\Context $context, 
        \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory) {
    $this->orderCollectionFactory = $orderCollectionFactory;
public function execute()
    $orders = $this->orderCollectionFactory->create()
    ->addAttributeToFilter('customer_email', '[email protected]')
    ->addAttributeToFilter('customer_is_guest', '1');
    foreach ($orders as $items) {
        echo $items->getEntityId() . '<pre>';

It will print the increment id of the above order collection filter.

Hope this helps. Peace :)

Your Answer

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

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