---
title: "How to Apply OR Conditions to Collection in Magento 2?"
url: "https://magecomp.com/blog/apply-or-conditions-to-collection-magento-2/"
date: "2022-08-05T16:17:44+00:00"
modified: "2025-02-19T05:31:37+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 287
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "You can apply OR conditions to Magento 2 collection. Learn how to use OR conditions for Magento 2 addFieldToFilter and addAttributeToFilter."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: How to Add a Custom Image Field in Bundle Product Selection"
    url: "https://magecomp.com/blog/magento-2-add-custom-image-field-in-bundle-product-selection/"
  - title: "How to Display Complex Error &#038; Success Messages in Magento 2"
    url: "https://magecomp.com/blog/display-complex-error-success-messages-magento-2/"
  - title: "How to Add Newsletter Subscriber Programmatically in Magento 2?"
    url: "https://magecomp.com/blog/add-newsletter-subscriber-programmatically-magento-2/"
---

# How to Apply OR Conditions to Collection in Magento 2?

_Published: August 5, 2022_  
_Author: Dhiren Vasoya_  

![How to Apply OR Conditions to Collection in Magento 2](https://magecomp.com/blog/wp-content/uploads/2022/08/How-to-Apply-OR-Conditions-to-Collection-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In this tutorial, I will be describing How to Apply OR Conditions to Collection in Magento 2.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

Collection in Magento 2 is used to retrieve objects of the same category like [**product collection**](https://magecomp.com/blog/get-product-collection-category-id-magento-2/), [**customer collection**](https://magecomp.com/blog/get-customer-collection-magento-2/), categories, etc. AND and OR are the Magento 2 collection conditions that can be applied to retrieve product data from the collection in Magento. AND is the default Magento 2 collection conditions.
In this tutorial, we will learn about Magento 2 addFieldToFilter and addAttributeToFilter OR conditions.
## Steps to Apply OR Conditions to Collection in Magento 2:
**Step 1:** Apply OR condition for Magento 2 **addAttributeToFilter** collection
```
protected  $_productCollection;

public function __construct(
   MagentoCatalogModelResourceModelProductCollection $productCollection)
{
     $this->_productCollection = $productCollection;
}

public function getProductCollection()
{
     $this->_productCollection->addAttributeToFilter(array(
     array(
          'attribute' => 'sku',
          'like' => '24MB%’),
          array(
               'attribute' => 'type_id',
               'eq' => 'simple')
          ));

     echo $this->_productCollection->getSelect();
}
```

**Output:**

```
SELECT `e`.* FROM `catalog_product_entity` AS `e` WHERE ((`e`.`sku` LIKE '24MB%') OR (`e`.`type_id` = 'simple'))
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 2:** Apply OR condition for Magento 2 **addFieldToFilter** collection
```
protected  $_orderCollection;

public function __construct(
   MagentoSalesModelResourceModelOrderCollection $orderCollection)
{
     $this->_orderCollection = $orderCollection;
}

public function getOrderCollection()
{
     $this->_orderCollection->addAttributeToFilter(array(
     array(
          'attribute' => 'sku',
          'like' => '24MB%’),
          array(
               'attribute' => 'type_id',
               'eq' => 'simple')
          ));

     echo $this->_orderCollection->getSelect();
}
```

**Output:**

```
SELECT `main_table`.* FROM `sales_order` AS `main_table` WHERE ((`customer_is_guest` = 1) OR (`status` = 'pending'))
```

## [![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

## Conclusion:
Accordingly, you can apply OR conditions for addAttributeToFilter and addFieldToFilter Magento 2. If you have any doubt about the addAttributeToFilter and addFieldToFilter Magento 2 collection conditions, freely contact me through the comment part. Share the article with your friends and keep yourself updated with the latest Magento solutions by us.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/apply-or-conditions-to-collection-magento-2/](https://magecomp.com/blog/apply-or-conditions-to-collection-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-23 13:39:58 UTC_  
