Answers.Body: <p>Using <code>craft.app.request.getParam</code> will only work on the initial request. Sprig populates variables from parameters by default, so you should be able to replace the first three lines with the following, and that should solve your issue.</p>
  <pre><code>  {% set category = category|default(null) %}
    {% set organisation = organisation|default(null) %}
    {% set topic = topic|default(null) %}
  </code></pre>
  <p>You’ll also need to ensure that their values are submitted in subsequent requests triggered by the load more button. To do so, you can add them as parameters as follows.</p>
  <pre><code>{% set params = { 
      category: category, 
      organisation: organisation, 
      topic: topic,
  } %}
  &lt;div sprig s-val:offset=&quot;{{ offset + limit }}&quot; s-target=&quot;this&quot; s-swap=&quot;outerHTML&quot; class=&quot;news-footer&quot;
      s-vals=&quot;{{ params|json_encode }}&quot;
  &gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-31T12:45:30.470Z
Answers.Text: Thanks! But no i still get the other entries after "load more"
Answers.UserDisplayName: Marcel Boer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-31T13:01:30.180Z
Answers.Text: So it seems like that it ignores the "relatedTo" when i set "topicsEntries" when you click "load more" @BenCroker
Answers.UserDisplayName: Marcel Boer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-01T15:05:40.590Z
Answers.Text: I updated my answer with some extra code, does that help?
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-25T13:10:26.987Z
Answers.Text: Yes it did :) Thank youu!
Answers.UserDisplayName: Marcel Boer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-30T12:48:37.973Z
Answers.LastActivityDate: 2023-09-04T10:03:43.900Z
Answers.LastEditDate: 2023-09-04T10:03:43.900Z
Answers.UserDisplayName: Ben Croker
Answers.Body: <p>When using the Sprig plugin to &quot;load more&quot; entries, you'll want to make sure you're correctly maintaining your filter parameters across requests. If you're loading more entries but it includes entries from categories other than what was originally filtered, it's possible that your subsequent Sprig requests aren't carrying over the original filter parameters.</p>
  <p>When you make a Sprig request, it doesn't automatically know about the original filter parameters you set. You have to explicitly pass them again in the Sprig context so that the new batch of entries is filtered the same way as the first batch.</p>
  <p>Here's one approach to make sure the category filter stays in effect:</p>
  <p>Pass the original category parameter (and other filter parameters if needed) to your Sprig component as attributes. These will be available in the s-val attribute or as parameters in your Sprig include.</p>
  <p>Include the filter parameters in your &quot;Load More&quot; button to make sure they are applied in subsequent requests.</p>
  <p>Here's how you might modify your &quot;Load More&quot; button to include the category and other parameters:</p>
  <pre><code>&lt;div sprig 
       s-val:offset=&quot;{{ offset + limit }}&quot;
       s-val:category=&quot;{{ category }}&quot; 
       s-val:organisation=&quot;{{ organisation }}&quot;
       s-val:topic=&quot;{{ topic }}&quot;
       s-target=&quot;this&quot; 
       s-swap=&quot;outerHTML&quot; 
       class=&quot;news-footer&quot;&gt;
    &lt;button class=&quot;button button-theme-transparent&quot;&gt;
      &lt;span class=&quot;button-title&quot;&gt;Mehr anzeigen&lt;/span&gt;
    &lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Now in your Sprig component, you should be able to access these values and use them to filter your entries.</p>
  <p>Another approach is to encapsulate all of this logic within a Sprig component that knows how to filter entries based on URL parameters. This would involve moving your current code into a reusable Sprig component.</p>
  <p>Also, note that you have a typographical issue with rel=”noopener noreferrer” in your code. The quotation marks should be consistent. So it should be rel=&quot;noopener noreferrer&quot;.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-15T15:27:20.057Z
Answers.LastActivityDate: 2023-09-15T15:27:20.057Z
Answers.UserDisplayName: JBrew30
Body: <p>so i filter some entries via the url parameters... that works fine. But if i load more entries (based on the category parameter), the result includes also all other entries with other categories... but of course i just wanna load more entries based on that one category parameter... any ideas? :)</p>
  <pre><code>  {% set category = craft.app.request.getParam('category') %}
    {% set organisation = craft.app.request.getParam('organisation') %}
    {% set topic = craft.app.request.getParam('topic') %}
  
    {% set organisationCat = organisation ? craft.categories.group('organisation').slug(organisation).one() %}
    {% set categoryCat = category ? craft.categories.group('category').slug(category).one() %}
    {% set topicCat = topic ? craft.categories.group('topic').slug(topic).one() %}
  
    {% set organisationParam = organisationCat ? {targetElement: organisationCat} %}
    {% set categoryParam = categoryCat ? {targetElement: categoryCat} %}
    {% set topicParam = topicCat ? {targetElement: topicCat} %}
  
    {% set relationParams = [organisationParam, categoryParam, topicParam]|filter %}
  
    {% set topicsEntries = craft.entries({
      section: 'topics',
      relatedTo: relationParams ? ['and']|merge(relationParams) : null,
    }) %}
  
    {% set offset = offset ?? 0 %}
    {% set limit = 3 %}
  
    {% set allTopicsEntries = topicsEntries.offset(offset).limit(limit) %}
    {% set allTopicsOutputEntries = allTopicsEntries.all() %}
  
    {# Loop and output #}
    {% for topic in allTopicsOutputEntries %}
      &lt;div class=&quot;grid-item&quot;&gt;
        {% if topic.topicLink is defined and topic.topicLink|length %}
          &lt;a class=&quot;card-topic&quot; href=&quot;{{topic.topicLink}}&quot; target=&quot;_blank&quot; rel=”noopener noreferrer”&gt;
            &lt;div class=&quot;card-topic__wrapper&quot;&gt;
              {% if topic.catTopic is defined and topic.catTopic|length %}
                &lt;span class=&quot;card-topic__toptitle&quot;&gt;{{topic.catTopic.one().title}}&lt;/span&gt;
              {% endif %}
              {% if topic.topicTitle is defined and topic.topicTitle %}
                &lt;h3 class=&quot;card-topic__title&quot;&gt;{{topic.topicTitle}}&lt;/h3&gt;
              {% else %}
                &lt;h3 class=&quot;card-topic__title&quot;&gt;{{topic.title}}&lt;/h3&gt;
              {% endif %}
              {% if topic.topicText is defined and topic.topicText|length %}
                &lt;div class=&quot;card-topic__text&quot;&gt;
                  &lt;p&gt;{{topic.topicText}}&lt;/p&gt;
                &lt;/div&gt;
              {% endif %}
              &lt;div class=&quot;card-topic__button&quot;&gt;
                &lt;span class=&quot;button-circle button-circle-theme-bright&quot;&gt;
                  &lt;span class=&quot;button-circle__icon&quot;&gt;
                    &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 14 12&quot; style=&quot;enable-background:new 0 0 14 12&quot; xml:space=&quot;preserve&quot;&gt;&lt;path d=&quot;m7 11 5-5-5-5&quot; style=&quot;fill:none;stroke:#1a0d3d;stroke-width:2;stroke-linecap:round&quot;/&gt;&lt;path d=&quot;M1 5c-.6 0-1 .4-1 1s.4 1 1 1V5zm11 0H1v2h11V5z&quot; style=&quot;fill:#1a0d3d&quot;/&gt;&lt;/svg&gt;
                  &lt;/span&gt;
                &lt;/span&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/a&gt;
        {% endif %}
      &lt;/div&gt;
    {% endfor %}
  
    {# If the total entry count is greater than the number that has been displayed#}
    {% if allTopicsEntries.count() &gt; offset + allTopicsOutputEntries|length %}
      {# Increments `offset` by the value of `limit` and swaps itself out on click #}
      &lt;div sprig s-val:offset=&quot;{{ offset + limit }}&quot; s-target=&quot;this&quot; s-swap=&quot;outerHTML&quot; class=&quot;news-footer&quot;&gt;
        &lt;button class=&quot;button button-theme-transparent&quot;&gt;
          &lt;span class=&quot;button-title&quot;&gt;Mehr anzeigen&lt;/span&gt;
        &lt;/button&gt;
      &lt;/div&gt;
    {% endif %}
  </code></pre>
  
Tags: <plugin-sprig>
Title: Load More Entries based on Parameter Category Filtering
ThreadText: # Load More Entries based on Parameter Category Filtering
  
  (Asked by: username_0 on 2023-08-30)
  
  so i filter some entries via the url parameters... that works fine. But if i load more entries (based on the category parameter), the result includes also all other entries with other categories... but of course i just wanna load more entries based on that one category parameter... any ideas? :)
  
  ```
    {% set category = craft.app.request.getParam('category') %}
    {% set organisation = craft.app.request.getParam('organisation') %}
    {% set topic = craft.app.request.getParam('topic') %}
  
    {% set organisationCat = organisation ? craft.categories.group('organisation').slug(organisation).one() %}
    {% set categoryCat = category ? craft.categories.group('category').slug(category).one() %}
    {% set topicCat = topic ? craft.categories.group('topic').slug(topic).one() %}
  
    {% set organisationParam = organisationCat ? {targetElement: organisationCat} %}
    {% set categoryParam = categoryCat ? {targetElement: categoryCat} %}
    {% set topicParam = topicCat ? {targetElement: topicCat} %}
  
    {% set relationParams = [organisationParam, categoryParam, topicParam]|filter %}
  
    {% set topicsEntries = craft.entries({
      section: 'topics',
      relatedTo: relationParams ? ['and']|merge(relationParams) : null,
    }) %}
  
    {% set offset = offset ?? 0 %}
    {% set limit = 3 %}
  
    {% set allTopicsEntries = topicsEntries.offset(offset).limit(limit) %}
    {% set allTopicsOutputEntries = allTopicsEntries.all() %}
  
    {# Loop and output #}
    {% for topic in allTopicsOutputEntries %}
      <div class="grid-item">
        {% if topic.topicLink is defined and topic.topicLink|length %}
          <a class="card-topic" href="{{topic.topicLink}}" target="_blank" rel=”noopener noreferrer”>
            <div class="card-topic__wrapper">
              {% if topic.catTopic is defined and topic.catTopic|length %}
                <span class="card-topic__toptitle">{{topic.catTopic.one().title}}</span>
              {% endif %}
              {% if topic.topicTitle is defined and topic.topicTitle %}
                <h3 class="card-topic__title">{{topic.topicTitle}}</h3>
              {% else %}
                <h3 class="card-topic__title">{{topic.title}}</h3>
              {% endif %}
              {% if topic.topicText is defined and topic.topicText|length %}
                <div class="card-topic__text">
                  <p>{{topic.topicText}}</p>
                </div>
              {% endif %}
              <div class="card-topic__button">
                <span class="button-circle button-circle-theme-bright">
                  <span class="button-circle__icon">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 12" style="enable-background:new 0 0 14 12" xml:space="preserve"><path d="m7 11 5-5-5-5" style="fill:none;stroke:#1a0d3d;stroke-width:2;stroke-linecap:round"/><path d="M1 5c-.6 0-1 .4-1 1s.4 1 1 1V5zm11 0H1v2h11V5z" style="fill:#1a0d3d"/></svg>
                  </span>
                </span>
              </div>
            </div>
          </a>
        {% endif %}
      </div>
    {% endfor %}
  
    {# If the total entry count is greater than the number that has been displayed#}
    {% if allTopicsEntries.count() > offset + allTopicsOutputEntries|length %}
      {# Increments `offset` by the value of `limit` and swaps itself out on click #}
      <div sprig s-val:offset="{{ offset + limit }}" s-target="this" s-swap="outerHTML" class="news-footer">
        <button class="button button-theme-transparent">
          <span class="button-title">Mehr anzeigen</span>
        </button>
      </div>
    {% endif %}
  
  ```
  
  **Tags:** plugin-sprig
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-08-30. Score: 2 | Accepted answer
  
  Using `craft.app.request.getParam` will only work on the initial request. Sprig populates variables from parameters by default, so you should be able to replace the first three lines with the following, and that should solve your issue.
  
  ```
    {% set category = category|default(null) %}
    {% set organisation = organisation|default(null) %}
    {% set topic = topic|default(null) %}
  
  ```
  
  You’ll also need to ensure that their values are submitted in subsequent requests triggered by the load more button. To do so, you can add them as parameters as follows.
  
  ```
  {% set params = { 
      category: category, 
      organisation: organisation, 
      topic: topic,
  } %}
  <div sprig s-val:offset="{{ offset + limit }}" s-target="this" s-swap="outerHTML" class="news-footer"
      s-vals="{{ params|json_encode }}"
  >
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks! But no i still get the other entries after "load more"  
  > **username_0**: So it seems like that it ignores the "relatedTo" when i set "topicsEntries" when you click "load more" @username_1  
  > **username_1**: I updated my answer with some extra code, does that help?  
  > **username_0**: Yes it did :) Thank youu!  
  
  ---
  
  ### Answer by username_2 on 2023-09-15. Score: 0
  
  When using the Sprig plugin to "load more" entries, you'll want to make sure you're correctly maintaining your filter parameters across requests. If you're loading more entries but it includes entries from categories other than what was originally filtered, it's possible that your subsequent Sprig requests aren't carrying over the original filter parameters.
  
  When you make a Sprig request, it doesn't automatically know about the original filter parameters you set. You have to explicitly pass them again in the Sprig context so that the new batch of entries is filtered the same way as the first batch.
  
  Here's one approach to make sure the category filter stays in effect:
  
  Pass the original category parameter (and other filter parameters if needed) to your Sprig component as attributes. These will be available in the s-val attribute or as parameters in your Sprig include.
  
  Include the filter parameters in your "Load More" button to make sure they are applied in subsequent requests.
  
  Here's how you might modify your "Load More" button to include the category and other parameters:
  
  ```
  <div sprig 
       s-val:offset="{{ offset + limit }}"
       s-val:category="{{ category }}" 
       s-val:organisation="{{ organisation }}"
       s-val:topic="{{ topic }}"
       s-target="this" 
       s-swap="outerHTML" 
       class="news-footer">
    <button class="button button-theme-transparent">
      <span class="button-title">Mehr anzeigen</span>
    </button>
  </div>
  
  ```
  
  Now in your Sprig component, you should be able to access these values and use them to filter your entries.
  
  Another approach is to encapsulate all of this logic within a Sprig component that knows how to filter entries based on URL parameters. This would involve moving your current code into a reusable Sprig component.
  
  Also, note that you have a typographical issue with rel=”noopener noreferrer” in your code. The quotation marks should be consistent. So it should be rel="noopener noreferrer".
  
  
  ---
  
  