Hello,
I am trying to display all the tags created with a multiselect field with a unique id which is the “slug version” of the tag. Let’s say for instance that I have the tag “Exhibition design” and it needs to be displayed as a div that has and ID with a value of “exhibition-design”. I need this for a filtering system I developed on my own.
I actually did that with a foreach loop and a pluck function.
Result: sometimes the foreach loops both the slugified version and the normal one with the same ID.
For example it displays both “Exhibition design” and “exhibition-design” divs (that have the same “exhibition-design” ID).
What I want to achieve:
The foreach loop should only display the first tag (the one with the normal name) <div id="exhibition-design">Exhibition design</div>
I think the problem is that your category field contains values like Exhibition design and exhibition-design, otherwise you wouldn’t get the output you get from your code.
Not related to your issue, but instead of modifying the $singletag variable in multiple steps, you can use
Hi @texnixe,
as I wrote in the reply to @Adspectus there is no double category in the multiselect blueprint.
Could it be possible that categories added previously (but not present in the multiselect anymore) are saved in some way and get counted and displayed in the foreach loop despite they should not be there anymore?
Looks like you have changed the option values after they were first stored (otherwise, there shouldn’t be those near duplicates)? Check what is really stored in the content files and correct as needed. But since the values you want to store are already sluggified, I wonder why you want to sluggify them again.
Hi @texnixe,
the sluggified versions of the tags were probably entered in the multiselect predefined options in the beginning but they are not ther anymore as you can see from the multiselect options I sent you. I simply changed my mind and decided to use different tags at a certain point.
Why if I delete a multiselect option from the blueprint it is still displayed in the tags list? I thought that when someone deletes a tag it wouldn’t be displayed again (and it is not assigned to any post).
I cannot remove that suggified tag because it already not there.
What should I do to remove that from the multiselect tags list?
If your array contains home and Home or exhibition-design and Exhibition design this means that these values are stored in your content files, otherwise they wouldn’t be there.
If you select a value and later change your mind, the previously stored value will stay in your content unless you remove these values using a hook or a script, or when you next make changes to the page.
Thank you @texnixe,
I checked the “content” folder and found out that the wrong values were actually stored there.
Of course something changed on the way but I thought that when a tag is deleted from its selector it would be deleted also in the content. It seemed logical to me.
So basically when “exhibition-design” was already stored it wasn’t replaced by “Exhibition design” after I deleted “exhibition-design” option from the multiselect and added “Exhibition design” there. What happened is that in the content folder the “exhibition-design” option was still there and “Exhibition design” was missing. That is what confused me.