下拉列表元素上的选项值重复
I'm using this codes for listing custom field values into drop-down list element on this category in Wordpress (screenshot is here what i'm point out).
So there are duplicate items on drop-down list and how i can delete duplicate entries on list?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最好的办法是在将它们打印到列表之前检查是否有重复项。如果它们总是排序的(如您的示例中所示),那么您只需跟踪您最后使用的值是什么就可以轻松地做到这一点。确保当前值不匹配,然后显示它并将其指定为新的最后一个值。
Your best bet is to check for duplicates before you print them to the list. If they are always sorted (as it appears in your example), then you can easily do this just by keeping track of what was the last value you used. Make sure the current value does not match, then display it and assign it as the new last value.
删除重复的自定义字段:WordPress › 自定义字段分类法 « WordPress 插件
Remove duplicate custom fields: WordPress › Custom Field Taxonomies « WordPress Plugins
我从 IRC 人员 (alxndr) 那里找到了解决方案。 这个示例解决了我的问题。
I found a solution from an IRC person (alxndr). This example is solved my problem.
检查这里:
http://www.martienus.com/code/javascript- remove-duplicates-from-array.html
或 google '删除重复的 javascript' 或类似的东西。
所以基本上,将下拉列表中的所有内容读入数组,删除下拉列表中的所有内容,对数组进行重复数据删除,然后将结果添加到下拉列表中以实现快速而肮脏的操作...
我相信您可以稍后再回来执行此操作这一切都是通过只从下拉列表中删除内容而不删除其他所有内容,然后将它们添加回来作为提高效率的练习。
Check here:
http://www.martienus.com/code/javascript-remove-duplicates-from-array.html
or google 'delete duplicates javascript' or some such.
So basically, read everything in the dropdown into an array, delete everything in the dropdown, de-dupe the array, and add the results into the dropdown for the quick and dirty...
I'm sure you could come back later and do it all by only deleting things from the dropdown without deleteing everything else and adding them back as an exercise in efficiency later.