最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Do not change the order of the tags in the editor

programmeradmin0浏览0评论

I have a list posts by tag, but the relation is not relevant because first look for the posts with the first tags stored alphabetically, and not the first main tag, that is to say for me the order of the tags are key because the first tag is the most relevant. So when saving everything, it is sorted alphabetically and this does not help me, any idea how to alter this?

I have a list posts by tag, but the relation is not relevant because first look for the posts with the first tags stored alphabetically, and not the first main tag, that is to say for me the order of the tags are key because the first tag is the most relevant. So when saving everything, it is sorted alphabetically and this does not help me, any idea how to alter this?

Share Improve this question asked Apr 16, 2020 at 21:07 LΞИIИLΞИIИ 1947 bronze badges 2
  • 1 It may be easier to create your own custom taxonomy than try to alter Core alphabetization. – WebElaine Commented Apr 16, 2020 at 21:18
  • 1 Terms/Tags aren't ordered, any order you see in the editor is purely circumstantial, there is no order mechanism in the database for terms. If you want to give special meaning to a term, you need to do so explicitly, e.g. store the term ID of the significant term in post meta – Tom J Nowell Commented Apr 16, 2020 at 21:18
Add a comment  | 

2 Answers 2

Reset to default 2

Terms/Tags aren't ordered.

To help make the terms easier to read, the editor will list them alphabetically, but that isn't because they're ordered alphabetically in the database. It's because a piece of javascript sorted the terms in the UI control.

There is no order, only the order you give them. Fundamentally terms have no order. Any order you see in the editor is purely circumstantial, there is no order mechanism in the database for terms.

If you want to give special meaning to a term, you need to do so explicitly, e.g. store the term ID of the significant term in post meta. You cannot rely on order, as terms do not have order.

I faced the same issue and saw that while there is the wp_term_relationships table, it doesn't get properly updated with the tags' order on post update. As a workaround, I hooked into the rest_after_insert_this-post_type to update the order myself. Here is a more detailed explanation of what I did, along with some code that seems to work fine so far.

发布评论

评论列表(0)

  1. 暂无评论