# CMS Filter, Results Count: Doesn't update with filters?

**URL:** <https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654>\
**Category:** Attributes\
**Created:** [May 17, 2023, 6:01pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654 "2023-05-17T18:01:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![luke](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/luke/32/328_2.png) [@luke](https://forum.finsweet.com/u/luke)\
**Post date:** [May 17, 2023, 6:01pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/1 "2023-05-17T18:01:57Z")

</div>

I have results count working with CMS Filter to display the number of items with a CMS tag applied. I am wondering if it is possible to keep that number displayed rather than having it update when other filters are applied.

For example, when you load the page tag1 would show 10 items, tag2 shows 12 items. If I use the checkbox to select items with tag1, tag2 count goes from 12 to 0.

I am wondering how I could display the counts, but keep the 10 & 12 even with the filters applied.

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [May 17, 2023, 6:30pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/2 "2023-05-17T18:30:12Z")

</div>

Hey @luke! Could you share a live site link?

---

<div class="post-metadata">

**Author:** ![luke](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/luke/32/328_2.png) [@luke](https://forum.finsweet.com/u/luke)\
**Post date:** [May 18, 2023, 4:38pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/3 "2023-05-18T16:38:01Z")

</div>

@Support-Luis

of course! I have been testing on a finsweet template:

> **[CMS Filter Example | Attributes by Finsweet](https://webflow-cms-filter-220762.webflow.io/)**
>
> Create advanced and complex no-code filter systems for Webflow CMS Collection List content

In this example I would want the number of car “make” to stay the number it shows when it loads, and not update when the filters are changed.

---

<div class="post-metadata">

**Author:** ![luke](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/luke/32/328_2.png) [@luke](https://forum.finsweet.com/u/luke)\
**Post date:** [June 9, 2023, 4:22pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/4 "2023-06-09T16:22:46Z")

</div>

@Support-Luis I am starting to build this out for a client next week, any chance there is a solution for this?

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [June 9, 2023, 10:15pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/5 "2023-06-09T22:15:56Z")

</div>

Hey @luke! This was a fun challenge and I got something that works but you’ll need to fine-tune it as it currently relies on a timeout… not the best option. but it is a starting ground for you. Some modifications to your page structure where needed:

1. remove the `fs-cmsfilter-element="filter-results-count"` attribute from the result text and replace it with the `.results-text` class
2. add this script to your `</body>`

```js
<script>
  setTimeout(function () {
    window.fsAttributes = window.fsAttributes || [];
    window.fsAttributes.push([
      'cmsfilter',
      function (filterInstances) {
        const [filterInstance] = filterInstances;
        const filtersData = filterInstance.filtersData;
        let resultsArray = [];

        filtersData.forEach(function (element) {
          const elements = element.elements;
          elements.forEach(function (element) {
            let filterValue = element.value;
            let resultsNumber = element.resultsCount;
            resultsArray.push({ filterName: filterValue, filterResults: resultsNumber });
          });
        });

        resultsArray.forEach(function (filter) {
          var elements = Array.from(document.querySelectorAll('[fs-cmsfilter-field]')).filter(
            function (element) {
              return element.textContent.trim() === filter.filterName;
            }
          );

          elements.forEach(function (element) {
            var resultsTextElement = element.nextElementSibling
              ? element.nextElementSibling.querySelector('.results-text')
              : null;
            if (resultsTextElement) {
              resultsTextElement.textContent = filter.filterResults;
            }
          });
        });
      },
    ]);
  }, 2500);
</script>

```

---

<div class="post-metadata">

**Author:** ![luke](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/luke/32/328_2.png) [@luke](https://forum.finsweet.com/u/luke)\
**Post date:** [June 15, 2023, 11:55am UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/6 "2023-06-15T11:55:26Z")

</div>

@Support-Luis awesome, thanks so much for digging in on this!

I just added it to my page and it seems to be working perfectly! I’ll keep fine tuning, but for now this should work!

---

<div class="post-metadata">

**Author:** ![luke](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/luke/32/328_2.png) [@luke](https://forum.finsweet.com/u/luke)\
**Post date:** [June 15, 2023, 12:18pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/7 "2023-06-15T12:18:47Z")

</div>

@Support-Luis as I have been working through it I found one very strange bug. For one of my filters, it displays a count of 0 even if I have it tagged to that filter. Clicking on the filter works, it just says that there are zero items with that tag. here is a screenshot of what I mean:

 ![Screenshot 2023-06-15 at 7.14.59 AM](https://europe1.discourse-cdn.com/flex013/uploads/finsweet1/original/1X/1ef5e850925615fcbe2e85a45c09f44532448b8b.png)

There are four items in the collection. Under “services” you can see that all four are being counted.

Under Divisions, I do have one tagged to Federal. Like I said, it works to display it on the list if I select it, it just shows the count of 0! I tried deleting the tag and re-adding it, I tried tagging them all as Federal; nothing I do seems to work here. There are actually 5 categories on the page, four of them work & count just fine, and this one tag doesn’t!

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [June 15, 2023, 3:59pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/8 "2023-06-15T15:59:05Z")

</div>

Hey @luke you can always dm me the page link and I’ll help you debug 💪

---

<div class="post-metadata">

**Author:** ![marcel](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/marcel/32/408_2.png) [@marcel](https://forum.finsweet.com/u/marcel)\
**Post date:** [January 16, 2024, 7:15pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/9 "2024-01-16T19:15:08Z")

</div>

@Support-Luis Hi Luis, I am trying to do the same thing. Having a result count that stays fixed. I have added your code and the extra class, but it is not working. Would you mind looking into it for me?

Here is a link:  
[https://tbwa-agc.webflow.io/news](https://tbwa-agc.webflow.io/news)

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [January 17, 2024, 12:28pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/10 "2024-01-17T12:28:14Z")

</div>

Hey there @marcel! Your Structure seems to be a little different than what Luke was using.

I’ve only removed the `.querySelector` from the code that targeted the text element and it seems to be working as expected.

Here is the code that adjusts to your setup.

```js
<script>
  setTimeout(function () {
    window.fsAttributes = window.fsAttributes || [];
    window.fsAttributes.push([
      'cmsfilter',
      function (filterInstances) {
        const [filterInstance] = filterInstances;
        const filtersData = filterInstance.filtersData;
        let resultsArray = [];

        filtersData.forEach(function (element) {
          const elements = element.elements;
          elements.forEach(function (element) {
            let filterValue = element.value;
            let resultsNumber = element.resultsCount;
            resultsArray.push({ filterName: filterValue, filterResults: resultsNumber });
          });
        });

        resultsArray.forEach(function (filter) {
          let elements = Array.from(document.querySelectorAll('[fs-cmsfilter-field]')).filter(
            function (element) {
              return element.textContent.trim() === filter.filterName;
            }
          );

          elements.forEach(function (element) {
            let resultsTextElement = element.nextElementSibling ? element.nextElementSibling : null;
            if (resultsTextElement) {
              resultsTextElement.textContent = filter.filterResults;
            }
          });
        });
      },
    ]);
  }, 2500);
</script>

```

---

<div class="post-metadata">

**Author:** ![marcel](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/marcel/32/408_2.png) [@marcel](https://forum.finsweet.com/u/marcel)\
**Post date:** [January 18, 2024, 4:09pm UTC](https://forum.finsweet.com/t/cms-filter-results-count-doesnt-update-with-filters/654/11 "2024-01-18T16:09:40Z")

</div>

Perfect, thank you so much.
