Answers.Body: <p>I think you're misunderstanding what <code>with</code> does. Or I am. Ha!</p>
  
  <p>From what I understand <code>with</code> is for eager loading, but doesn't control anything in the relation itself. I don't think your relation makes any sense either because all you'll do is substitute a string into your spec variables.</p>
  
  <p>Try something more like:</p>
  
  <pre><code>{% set products = craft.commerce.products({
      relatedTo: [
          'and',
          CONDITION1,
          CONDITION2
      ],
      with: [
          fieldYouWantToShow,
          otherFieldYouWantToShow,
      ], 
      order: "title asc",
  }) %}
  </code></pre>
  
  <p>And your conditionals should be something like:</p>
  
  <pre><code>{ targetElement: category },
  { sourceElement: craft.entries.section('reviews').status(null) }
  </code></pre>
  
  <p>The bottom example here is what you're needing: <a href="https://craftcms.com/docs/relations" rel="nofollow noreferrer">https://craftcms.com/docs/relations</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-06T15:02:10.547Z
Answers.Text: I am with you Matt, `with` is for eager loading related elements. And before implementing it, @DarrylHardin needs to get the `relatedTo` param setup correctly for his needs. A good blog post on that topic that I can recommend: https://www.webstoemp.com/blog/combined-searches-and-filters-craft-cms/
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-06T14:48:46.197Z
Answers.LastActivityDate: 2017-07-06T19:26:42.437Z
Answers.LastEditDate: 2017-07-06T19:26:42.437Z
Answers.UserDisplayName: Matt Wilcox
Body: <p>I actually found this code on here <a href="https://craftcms.stackexchange.com/questions/14914/search-form-with-craft-commerce">Search Form with Craft Commerce</a>. I had a problem with this code pulling up products that didn't match, and then after creating a new product it worked for a bit and then broke and continued to only pull up the same ones, even if I got rid the values inside with[].</p>
  
  <p>So two questions, how do I enforce that the product has to match BOTH criteria in the with[] and does anyone have any clue about why it would stop refreshing products? I've tried clearing cache in both browser and craftcms. </p>
  
  <p>I apologize if this has been asked before, I've been through multiple previously asked questions with little luck.</p>
  
  <pre><code>{% set spec = craft.request.getParam('a') %}
  {% set spec2 = craft.request.getParam('b') %}
  {% set category = craft.categories.group('productSpecs') %}
  {% set products = craft.commerce.products({
              relatedTo: category,
               with: [
                  spec,
                  spec2,
              ], 
              order: "title asc",
          }) %}
  {% for product in products %}
      {{ product.title }}
  {% endfor %}
  </code></pre>
  
Tags: <categories><search><eager-loading><products>
Title: Enforce search match multiple parameters
ThreadText: # Enforce search match multiple parameters
  
  (Asked by: username_0 on 2017-07-06)
  
  I actually found this code on here [Search Form with Craft Commerce](https://craftcms.stackexchange.com/questions/14914/search-form-with-craft-commerce). I had a problem with this code pulling up products that didn't match, and then after creating a new product it worked for a bit and then broke and continued to only pull up the same ones, even if I got rid the values inside with[].
  
  So two questions, how do I enforce that the product has to match BOTH criteria in the with[] and does anyone have any clue about why it would stop refreshing products? I've tried clearing cache in both browser and craftcms.
  
  I apologize if this has been asked before, I've been through multiple previously asked questions with little luck.
  
  ```
  {% set spec = craft.request.getParam('a') %}
  {% set spec2 = craft.request.getParam('b') %}
  {% set category = craft.categories.group('productSpecs') %}
  {% set products = craft.commerce.products({
              relatedTo: category,
               with: [
                  spec,
                  spec2,
              ], 
              order: "title asc",
          }) %}
  {% for product in products %}
      {{ product.title }}
  {% endfor %}
  
  ```
  
  **Tags:** categories, search, eager-loading, products
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-07-06. Score: 3 | Accepted answer
  
  I think you're misunderstanding what `with` does. Or I am. Ha!
  
  From what I understand `with` is for eager loading, but doesn't control anything in the relation itself. I don't think your relation makes any sense either because all you'll do is substitute a string into your spec variables.
  
  Try something more like:
  
  ```
  {% set products = craft.commerce.products({
      relatedTo: [
          'and',
          CONDITION1,
          CONDITION2
      ],
      with: [
          fieldYouWantToShow,
          otherFieldYouWantToShow,
      ], 
      order: "title asc",
  }) %}
  
  ```
  
  And your conditionals should be something like:
  
  ```
  { targetElement: category },
  { sourceElement: craft.entries.section('reviews').status(null) }
  
  ```
  
  The bottom example here is what you're needing: <https://craftcms.com/docs/relations>
  
  > **Comments:**
  > **username_2**: I am with you username_1, `with` is for eager loading related elements. And before implementing it, @username_0 needs to get the `relatedTo` param setup correctly for his needs. A good blog post on that topic that I can recommend: https://www.webstoemp.com/blog/combined-searches-and-filters-craft-cms/  
  
  ---
  
  