Hello Webflow community!
I’m currently working on a project and trying to figure out if there’s a way to count the number of CMS items in Webflow that share a specific category selection. Here’s a breakdown of what I’m trying to achieve:
Objective: I have a CMS collection where each item can be assigned one or more categories. Now, I want to track and display the number of CMS items associated with a particular category and update another CMS collection with this count.
Question: Is there a method or a workaround in Webflow that allows me to dynamically count the number of CMS items with a certain category selected and then transfer that count to another CMS collection?
I appreciate any insights or guidance you can provide on this matter. Thank you in advance for your help!
Yes, with custom code.
I’ll guess that you’re setup is Item-multiref-to-Categories.
Your can emit your Items in a collection list, with a nested Categories list, and then use a script to tabulate the results.
As long as the number of Categories per Item is <= 5, and the total number of items is very reasonable, a few hundred max, you can build this out on a separate hidden page and then your script fetches it to get the counts.
If you want to push data back into a CMS collection you’ll need to use automation. You’d need that same custom code here to perform the same process- fetch your special data page, tabulate the results, and then update the CMS.
Note that the update CMS API’s require item ID’s, so you need those item ID’s as well, which aren’t accessible in collection lists or embeds. That means you need to create your own item ID field in your collection, and populate it using another automation that run on CMS item create events.
I build these types of systems often but Webflow is the most developer-unfriendly platform I’ve ever worked with. 95% of your effort will be in developing workaround infrastructure.
Thanks! Did it like you suggested. Automated it with Make (integromat) and it works fine.