<p>So I found that using the paginate tag would return all entries regardless of the keyword. I was able to get it to work by using the below results code. <em>(pagination still worked without the use of the pagination tag)</em></p>

<pre><code>{% set query = craft.request.getParam('q') %}

{% set tag = craft.tags.title(query).first() %}

{% set products = craft.commerce.products.search(query).limit(48) %}
{% if products|length %}
{% for product in products %}
   &lt;div class="item"&gt;
      &lt;div class="item-wrapper"&gt;
        &lt;figure class="he-3 cyan"&gt;
          &lt;img src="{{ product.presentationSlides.first().getUrl('mediaDetail') }}" alt="{{ product.name }}"&gt;
          &lt;div class="hover-icons"&gt;
            &lt;div class="hover-icons-wrapper"&gt;
              &lt;a href="{{ product.presentationSlides.first().getUrl('mediaLightbox') }}" class="magnific hidden-xs-down"&gt;
                &lt;i class="nc-icon-outline ui-1_zoom"&gt;&lt;/i&gt;
              &lt;/a&gt;
              &lt;a href="{{ product.url }}"&gt;
                &lt;i class="nc-icon-outline ui-2_link-71"&gt;&lt;/i&gt;
              &lt;/a&gt;
              &lt;a href="#" class="hidden-xs-down"&gt;
                &lt;i class="nc-icon-outline ui-2_favourite-28"&gt;&lt;/i&gt;
              &lt;/a&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/figure&gt;
      &lt;/div&gt;
    &lt;/div&gt;
{% endfor %}
{% else %}
   &lt;p&gt;No Results&lt;/p&gt;  
{% endif %}

/*pagination code */
</code></pre>

CC BY-SA 3.0
2016-12-25T21:44:57.797Z
2016-12-25T21:44:57.797Z
EDub
<p>This should work (set the limit to whatever you want/need):</p>

<pre><code>{% set tag = craft.tags.title(tagTitle).first() %}    

{% paginate craft.commerce.products.relatedTo(tag).limit(10) as pageInfo, products %}

    {% for product in products %}

        {{ product.title }} etc

    {% endfor %}

    {% if pageInfo.prevUrl %}&lt;a href="{{ pageInfo.prevUrl }}"&gt;Previous Page&lt;/a&gt;{% endif %}
    {% if pageInfo.nextUrl %}&lt;a href="{{ pageInfo.nextUrl }}"&gt;Next Page&lt;/a&gt;{% endif %}
</code></pre>

<p>For more on the pagination side of things, see: <a href="https://craftcms.com/docs/templating/paginate" rel="nofollow noreferrer">https://craftcms.com/docs/templating/paginate</a></p>

CC BY-SA 3.0
2016-12-22T02:57:22.883Z
2016-12-22T02:57:22.883Z
Jeremy Daalder
<p>this is my first Craft CMS &amp; Commerce build and I need some help with searching products by a tag field.</p>

<p>I have a tag field ("designTag") for each product and I would like to have a search bar that will only query the tag field for a specific product type ("designMedia") and return those products with matching or similar tag titles and also account for pagination. I can't seem to get it to work. Any help would be appreciated.
<br><br></p>

<p><strong>SEARCH FORM CODE:</strong><br></p>

<pre><code>&lt;form action="{{ url('design/keywords') }}"&gt;
    &lt;label&gt;Search By Keywords&lt;/label&gt;
    &lt;div class="append-icon"&gt;
        &lt;input type="search" name="q" class="form-control input-lg" placeholder="Enter Keyword..."&gt;
        &lt;button class="btn" type="submit"&gt;&lt;i class="nc-icon-outline ui-1_zoom"&gt;&lt;/i&gt;&lt;/button&gt;
    &lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p><strong>RESULTS CODE:</strong><br></p>

<pre><code>{% set tagTitle = craft.request.getParam('q') %}
{% set tag = craft.tags.title(tagTitle) %}    
{% set product = craft.commerce.products.search(query).order('score') %}

{% if product|length %}

{% paginate craft.commerce.products.type('designMedia').limit(48) as mediaProducts %}

{% for product in mediaProducts %}    
       &lt;div class="item"&gt;
          &lt;div class="item-wrapper"&gt;
            &lt;figure class="he-3 cyan"&gt;
              &lt;img src="{{ product.presentationSlides.first().getUrl('mediaDetail') }}" alt="{{ product.name }}"&gt;
              &lt;div class="hover-icons"&gt;
                &lt;div class="hover-icons-wrapper"&gt;
                  &lt;a href="{{ product.presentationSlides.first().getUrl('mediaLightbox') }}" class="magnific hidden-xs-down"&gt;
                    &lt;i class="nc-icon-outline ui-1_zoom"&gt;&lt;/i&gt;
                  &lt;/a&gt;
                  &lt;a href="{{ product.url }}"&gt;
                    &lt;i class="nc-icon-outline ui-2_link-71"&gt;&lt;/i&gt;
                  &lt;/a&gt;
                  &lt;a href="#" class="hidden-xs-down"&gt;
                    &lt;i class="nc-icon-outline ui-2_favourite-28"&gt;&lt;/i&gt;
                  &lt;/a&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/figure&gt;
          &lt;/div&gt;
        &lt;/div&gt;
{% endfor %}
{% else %}
    &lt;p&gt;No Results&lt;/p&gt;  
{% endif %}

/*pagination code */
{% endpaginate %}
</code></pre>

<templating><plugin-craftcommerce><search>
Search Commerce Products by Tags
# Search Commerce Products by Tags

(Asked by: username_0 on 2016-12-21)

this is my first Craft CMS & Commerce build and I need some help with searching products by a tag field.
I have a tag field ("designTag") for each product and I would like to have a search bar that will only query the tag field for a specific product type ("designMedia") and return those products with matching or similar tag titles and also account for pagination. I can't seem to get it to work. Any help would be appreciated.

SEARCH FORM CODE:

    Search By Keywords
    
        
        
    


RESULTS CODE:
{% set tagTitle = craft.request.getParam('q') %}
{% set tag = craft.tags.title(tagTitle) %}    
{% set product = craft.commerce.products.search(query).order('score') %}

{% if product|length %}

{% paginate craft.commerce.products.type('designMedia').limit(48) as mediaProducts %}

{% for product in mediaProducts %}    
       
          
            
              
              
                
                  
                    
                  
                  
                    
                  
                  
                    
                  
                
              
            
          
        
{% endfor %}
{% else %}
    No Results  
{% endif %}

/*pagination code */
{% endpaginate %}

**Tags:** templating, plugin-craftcommerce, search

---

## 2 answers

### Answer by username_0 on 2016-12-25. Score: 1 | Accepted answer

So I found that using the paginate tag would return all entries regardless of the keyword. I was able to get it to work by using the below results code. (pagination still worked without the use of the pagination tag)
{% set query = craft.request.getParam('q') %}

{% set tag = craft.tags.title(query).first() %}

{% set products = craft.commerce.products.search(query).limit(48) %}
{% if products|length %}
{% for product in products %}
   
      
        
          
          
            
              
                
              
              
                
              
              
                
              
            
          
        
      
    
{% endfor %}
{% else %}
   No Results  
{% endif %}

/*pagination code */


---

### Answer by username_1 on 2016-12-22. Score: 2

This should work (set the limit to whatever you want/need):
{% set tag = craft.tags.title(tagTitle).first() %}    

{% paginate craft.commerce.products.relatedTo(tag).limit(10) as pageInfo, products %}

    {% for product in products %}

        {{ product.title }} etc

    {% endfor %}

    {% if pageInfo.prevUrl %}Previous Page{% endif %}
    {% if pageInfo.nextUrl %}Next Page{% endif %}

For more on the pagination side of things, see: https://craftcms.com/docs/templating/paginate


---

