I want to filter some shop items using tags with checkboxes.
Right now I’m just getting all the items and have the tags set as a class per item, then setting the display to none and display to block accordingly with the checkbox and tag.
But I’m guessing there should be a better solution for this.
My solution will break with a lot of items and when for example the first 10 (max per page) posts don’t have the specific tag according to the checkbox, it will just show nothing as it hides the first 10 posts.
You could just get more posts and use your current approach. That has the advantage of doing one fetch to start and then checking and unchecking those boxes can have instant results. If you don’t have a lot of checkboxes and they’re all similarly common, just increasing how many posts you get might be enough. (Or get posts once for each tag, so that you make sure you have enough posts for all possible tag choices…)
Another option would be to re-fetch the wanted content after the user changes their selection. That would let you have the content API do the filtering for you. That’s going to be slower, since the browser has to talk to Ghost to get new cards every time the selection changes, but if you need a lot of specific filtering, that’s likely the way to go.