Answers.Body: <p>Try this:</p>
  <p>{{ sprig('_layouts/_categories/_loadMore', {limit: 6, category: category}) }}</p>
  <p>{{ sprig.script }}</p>
  <p>After query category is not defined.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-18T13:53:49.303Z
Answers.LastActivityDate: 2020-07-18T13:53:49.303Z
Answers.UserDisplayName: Pavel Pavlovich
Body: <p>I am trying out Sprig's <a href="https://putyourlightson.com/sprig-cookbook?page=2#load-more" rel="nofollow noreferrer">&quot;Load More&quot; Recipe</a> and I am trying to call up entries that are related to the current category page. But when I add <code>.relatedTo(category)</code> to the entry model, it doesn't work–it still just shows all the entries in the channel. I've used this <code>.relatedTo(category)</code> method elsewhere on the page (not using Sprig) and it works just fine. How can I call up only the entries that match the current category page in this Sprig recipe?</p>
  <p><strong>_category.twig</strong></p>
  <pre><code>{{ sprig('_layouts/_categories/_loadMore', {limit: 6}) }}
  {{ sprig.script }}
  </code></pre>
  <p><strong>_loadMore.twig</strong></p>
  <pre><code>{% set offset = offset ?? 6 %}
  {% set limit = limit ?? 10 %}
  
  {% set entries = craft.entries.section('aBetterPost').offset(offset).limit(limit).relatedTo(category).all() %}
  
  {% for entry in entries %}
  
      &lt;a href=&quot;{{ entry.url }}&quot; class=&quot;more-post&quot;&gt;
          &lt;div class=&quot;more-post-img-wrap&quot;&gt;
              {% set featuredImage = entry.featuredImage.one() %}
              &lt;img src=&quot;{{ featuredImage.getUrl }}&quot; class=&quot;more-post-img&quot;&gt;
              &lt;div class=&quot;red-overlay&quot;&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;more-post-content&quot;&gt;
              &lt;div class=&quot;more-post-title&quot;&gt;
                  &lt;h3&gt;{{ entry.title }}&lt;/h3&gt;
              &lt;/div&gt;
              &lt;div class=&quot;next-icon&quot;&gt;
                  &lt;i class=&quot;fas fa-chevron-right&quot;&gt;&lt;/i&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/a&gt;
  
  {% endfor %}
  
              
  {% if entries %}
  
  &lt;div class=&quot;load-button-wrap&quot; s-target=&quot;this&quot; s-swap=&quot;outerHTML&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;offset&quot; value=&quot;{{ offset + limit }}&quot;&gt;
      &lt;button class=&quot;load-button&quot; sprig&gt;Load More&lt;/button&gt;
  &lt;/div&gt;
  
  {% endif %}
  
  </code></pre>
  
Tags: <craft3><plugins><categories><relatedto>
Title: How to use categories with Sprig's "Load More" recipe
ThreadText: # How to use categories with Sprig's "Load More" recipe
  
  (Asked by: username_0 on 2020-07-18)
  
  I am trying out Sprig's ["Load More" Recipe](https://putyourlightson.com/sprig-cookbook?page=2#load-more) and I am trying to call up entries that are related to the current category page. But when I add `.relatedTo(category)` to the entry model, it doesn't work–it still just shows all the entries in the channel. I've used this `.relatedTo(category)` method elsewhere on the page (not using Sprig) and it works just fine. How can I call up only the entries that match the current category page in this Sprig recipe?
  
  **\_category.twig**
  
  ```
  {{ sprig('_layouts/_categories/_loadMore', {limit: 6}) }}
  {{ sprig.script }}
  
  ```
  
  **\_loadMore.twig**
  
  ```
  {% set offset = offset ?? 6 %}
  {% set limit = limit ?? 10 %}
  
  {% set entries = craft.entries.section('aBetterPost').offset(offset).limit(limit).relatedTo(category).all() %}
  
  {% for entry in entries %}
  
      <a href="{{ entry.url }}" class="more-post">
          <div class="more-post-img-wrap">
              {% set featuredImage = entry.featuredImage.one() %}
              <img src="{{ featuredImage.getUrl }}" class="more-post-img">
              <div class="red-overlay"></div>
          </div>
          <div class="more-post-content">
              <div class="more-post-title">
                  <h3>{{ entry.title }}</h3>
              </div>
              <div class="next-icon">
                  <i class="fas fa-chevron-right"></i>
              </div>
          </div>
      </a>
  
  {% endfor %}
  
              
  {% if entries %}
  
  <div class="load-button-wrap" s-target="this" s-swap="outerHTML">
      <input type="hidden" name="offset" value="{{ offset + limit }}">
      <button class="load-button" sprig>Load More</button>
  </div>
  
  {% endif %}
  
  ```
  
  **Tags:** craft3, plugins, categories, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-18. Score: 2 | Accepted answer
  
  Try this:
  
  {{ sprig('\_layouts/\_categories/\_loadMore', {limit: 6, category: category}) }}
  
  {{ sprig.script }}
  
  After query category is not defined.
  
  
  ---
  
  