Magento 2: How to add multiple AND conditions to one single attribute that could be used to join other condition groups?How to use FIND_IN_SET on a multiselect attribute filter with an AND condition?Adding attribute using JOIN to CollectionMagento 2: Product Repositories, Filter Groups, and `AND`Assign Multiple Filter to Single FilterGroup in magento 2Magento 2: addAttributeToFilter not returning any resultsMagento : Filter Collection by Attribute that Doesn't Exist or Null or another conditionMagento2: How to add multiple AND and OR conditions to filter/filterGroups?Magento 2 : how to addCategoriesFilter with AND condtion?Magento 1.9 collection multi conditionsMagento 2.3 custom conditions for attribute filter using addAttributeToFilter

Why can't I use =default for default ctors with a member initializer list

What speaks against investing in precious metals?

Wooden cooking layout

Is it possible to have a wealthy country without a middle class?

Has there been a multiethnic Star Trek character?

A IP can traceroute to it, but can not ping

Is this use of the expression "long past" correct?

SQL counting distinct over partition

Which languages would be most useful in Europe at the end of the 19th century?

Arriving at the same result with the opposite hypotheses

Is it legal for a bar bouncer to confiscate a fake ID

How is John Wick 3 a 15 certificate?

How can I get an unreasonable manager to approve time off?

How to communicate to my GM that not being allowed to use stealth isn't fun for me?

How can I make some of my chapters "come to life"?

Is White controlling this game?

Someone whose aspirations exceed abilities or means

Generate basis elements of the Steenrod algebra

What is the maximum number of net attacks that one can make in a round?

Certain search in list

Extreme flexible working hours: how to control people and activities?

Fixing obscure 8080 emulator bug?

How to use memset in c++?

Soft question: Examples where lack of mathematical rigour cause security breaches?



Magento 2: How to add multiple AND conditions to one single attribute that could be used to join other condition groups?


How to use FIND_IN_SET on a multiselect attribute filter with an AND condition?Adding attribute using JOIN to CollectionMagento 2: Product Repositories, Filter Groups, and `AND`Assign Multiple Filter to Single FilterGroup in magento 2Magento 2: addAttributeToFilter not returning any resultsMagento : Filter Collection by Attribute that Doesn't Exist or Null or another conditionMagento2: How to add multiple AND and OR conditions to filter/filterGroups?Magento 2 : how to addCategoriesFilter with AND condtion?Magento 1.9 collection multi conditionsMagento 2.3 custom conditions for attribute filter using addAttributeToFilter






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:



$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);


But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)



I have also tried to use search criteria builder, but still no luck so far.










share|improve this question
























  • Try like: $collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);

    – fmsthird
    May 31 at 7:50











  • @magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.

    – d.yuk
    May 31 at 8:45











  • why not try like $collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);

    – fmsthird
    May 31 at 8:49











  • creating two filter for the same attribute that might work

    – fmsthird
    May 31 at 8:49











  • can you try like $collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );

    – fmsthird
    May 31 at 9:12

















1















I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:



$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);


But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)



I have also tried to use search criteria builder, but still no luck so far.










share|improve this question
























  • Try like: $collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);

    – fmsthird
    May 31 at 7:50











  • @magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.

    – d.yuk
    May 31 at 8:45











  • why not try like $collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);

    – fmsthird
    May 31 at 8:49











  • creating two filter for the same attribute that might work

    – fmsthird
    May 31 at 8:49











  • can you try like $collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );

    – fmsthird
    May 31 at 9:12













1












1








1








I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:



$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);


But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)



I have also tried to use search criteria builder, but still no luck so far.










share|improve this question
















I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:



$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);


But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)



I have also tried to use search criteria builder, but still no luck so far.







magento2 product-collection eav-attributes






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 31 at 8:46







d.yuk

















asked May 31 at 7:28









d.yukd.yuk

247212




247212












  • Try like: $collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);

    – fmsthird
    May 31 at 7:50











  • @magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.

    – d.yuk
    May 31 at 8:45











  • why not try like $collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);

    – fmsthird
    May 31 at 8:49











  • creating two filter for the same attribute that might work

    – fmsthird
    May 31 at 8:49











  • can you try like $collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );

    – fmsthird
    May 31 at 9:12

















  • Try like: $collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);

    – fmsthird
    May 31 at 7:50











  • @magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.

    – d.yuk
    May 31 at 8:45











  • why not try like $collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);

    – fmsthird
    May 31 at 8:49











  • creating two filter for the same attribute that might work

    – fmsthird
    May 31 at 8:49











  • can you try like $collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );

    – fmsthird
    May 31 at 9:12
















Try like: $collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);

– fmsthird
May 31 at 7:50





Try like: $collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);

– fmsthird
May 31 at 7:50













@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.

– d.yuk
May 31 at 8:45





@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.

– d.yuk
May 31 at 8:45













why not try like $collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);

– fmsthird
May 31 at 8:49





why not try like $collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);

– fmsthird
May 31 at 8:49













creating two filter for the same attribute that might work

– fmsthird
May 31 at 8:49





creating two filter for the same attribute that might work

– fmsthird
May 31 at 8:49













can you try like $collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );

– fmsthird
May 31 at 9:12





can you try like $collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );

– fmsthird
May 31 at 9:12










0






active

oldest

votes












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276825%2fmagento-2-how-to-add-multiple-and-conditions-to-one-single-attribute-that-could%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276825%2fmagento-2-how-to-add-multiple-and-conditions-to-one-single-attribute-that-could%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form