{"id":593,"date":"2019-09-12T10:45:14","date_gmt":"2019-09-12T10:45:14","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/09\/12\/list-of-addattributetofilter-conditionals-in-magento\/"},"modified":"2025-05-22T16:00:31","modified_gmt":"2025-05-22T10:30:31","slug":"list-of-addattributetofilter-conditionals-in-magento","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/list-of-addattributetofilter-conditionals-in-magento\/","title":{"rendered":"List of addAttributeToFilter Conditionals In Magento"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Filter collections in Magento or Magento 2 using addAttributeToFilter conditionals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">addFieldToFilter is adding WHERE condition in Mysql question to get the collection from the database, allowing to filter the collections like product collection, category collection, and many more by custom conditions. In a parallel manner, the integration of an advanced feature like the <a title=\"How to Implement Multiselect Filter For Order Status in Magento 2 Order Grid\" href=\"https:\/\/meetanshi.com\/blog\/implement-multiselect-filter-for-order-status-in-magento-2-order-grid\/\">Multiselect Filter For Order Status in Magento 2 Order Grid<\/a> takes this concept further.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Developing is all about if, when and else most of the time! (Developers, don&#8217;t get offended  )<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may have to use conditions like equal, not equal, like, not like, in, not in, null, not null, greater than, less than, greater than equal to and less than equal to.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, using the addAttributeToFilter conditionals in Magento is effective when used with correct syntax. So, here&#8217;s the list!<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>Condition<\/strong><\/th><th><strong>Syntax<\/strong><\/th><th><strong>Example<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Equals<\/td><td><code>eq<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('status', array('eq' =&gt; 1));<\/code><\/td><\/tr><tr><td>Not Equals<\/td><td><code>neq<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('name', array('neq' =&gt; 'test-category'));<\/code><\/td><\/tr><tr><td>Like<\/td><td><code>like<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('name', array('like' =&gt; 'UX%'));<\/code><\/td><\/tr><tr><td>Not Like<\/td><td><code>nlike<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('name', array('nlike' =&gt; 'err-cat%'));<\/code><\/td><\/tr><tr><td>In<\/td><td><code>in<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('id', array('in' =&gt; array(1,4,98))));<\/code><\/td><\/tr><tr><td>Not In<\/td><td><code>nin<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('id', array('nin' =&gt; array(1,4,98))));<\/code><\/td><\/tr><tr><td>NULL<\/td><td><code>null<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('description', array('null' =&gt; true));<\/code><\/td><\/tr><tr><td>Not NULL<\/td><td><code>notnull<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('description', array('notnull' =&gt; true));<\/code><\/td><\/tr><tr><td>Greater Than<\/td><td><code>gt<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('id', array('gt' =&gt; 5));<\/code><\/td><\/tr><tr><td>Less Than<\/td><td><code>lt<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('id', array('lt' =&gt; 5));<\/code><\/td><\/tr><tr><td>Greater Than or Equals To<\/td><td><code>gteq<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('id', array('gteq' =&gt; 5));<\/code><\/td><\/tr><tr><td>Less Than or Equals To<\/td><td><code>lteq<\/code><\/td><td><code>$category-&gt;addAttributeToFilter('id', array('lteq' =&gt; 5));<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the post with fellow developers on social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Filter collections in Magento or Magento 2 using addAttributeToFilter conditionals. addFieldToFilter is adding WHERE condition in Mysql question to get the collection from the database,&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-593","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=593"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/593\/revisions"}],"predecessor-version":[{"id":15274,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/593\/revisions\/15274"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}