WordPress 自定义分类法 - 转换和过滤?
我遇到了 WP 自定义分类法的两个相当大的限制。
我有一个现有的博客,其中有数百篇帖子。我想追溯性地介绍自定义帖子类型和分类法。
我有一个非常复杂(且难以使用)的分类方案,如果我可以将给定类别下的帖子批量转换为自定义帖子类型或自定义分类法,那么这应该会使这一切变得容易。 (这是因为不同的内容类型有自己的类别 [文章、视频],不同的分类类型 [人物、地点] 也是如此)
我已经使用插件自定义帖子类型 ui 创建了我需要的自定义帖子类型和分类法。
第一步,更改某些帖子的帖子类型,可以通过使用转换帖子类型插件轻松完成。 (它允许您更改任何类别下帖子的帖子类型,这完全符合我的需求。)
第二步,将某些类别转换为自定义分类法(例如,将一组关于政治家的类别转换为“政治家”自定义分类法系列)事实证明这是不可能的。尽管任何希望将 WP3.0 的 CMSing 创新应用到现有博客的人显然都需要一个自定义分类转换器插件的类别(与自定义帖子类型转换的方式相同),但似乎没有一个类别。
所以我尝试走手动路线。如果我手动更改 wp_term_taxonomy 表中不同术语的“分类”字段 - 例如,从类别到政治家、自定义分类 - 该(前)类别下的所有帖子都会反映更新。如果您尝试编辑帖子,自定义分类元框会显示正确的术语。 (我还没有尝试编写自定义循环来查看帖子是否会显示在网站上,所以我不知道这是否有效,但我认为它可以。)到目前为止,一切都很好。或者看起来是这样:
第一个问题是,如果您转到自定义分类页面(相当于帖子下的“类别”或“帖子标签”页面),则不会显示任何术语在右边的表中。不过,如果你搜索它们,它们就会出现。
当我提出这个问题时,一位熟练的 WP 开发人员告诉我:
“我认为手动更新数据库的问题是 post 缓存不会更改。(请参阅 update_post_caches()。)我需要确保我”当我更改帖子类型时我也会这样做。”
不幸的是,我不太确定这意味着什么或如何处理。
第二个问题是,创建自定义分类并将其与帖子(或任何自定义帖子类型)关联起来不会像类别那样在查看帖子页面上生成过滤框。这使得自定义分类法几乎无法使用,至少就我而言是这样。
那么,有人知道如何将类别转换为自定义分类法(或者至少如果手动转换它们,如何让它们显示在后端)以及如何在帖子页面上添加分类法过滤器?
谢谢!
I've run into what seems like two pretty major limitations of WP's custom taxonomies.
I have an existing blog with hundreds of post. I'd like to retroactively introduce custom post types and taxonomies.
I have a very elaborate (and difficult to use) categorization scheme that should make this easy to do if I could just mass convert posts under a given category to a custom post types or custom taxonomy. (This is because different content types get their own categories [article, video,] as do different taxonomy types [people, places])
I've already created the custom post types and taxonomies that I need using the plugin custom post type ui.
The first step, changing the post type of certain posts, is easy to do by using the convert post types plugin. (It allows you to change the post type of posts under any category, which fits my needs perfectly.)
The second step, converting certain categories to custom taxonomies (say, a set of categories about politicians to a "politicians" custom taxonomy family) is proving to be bloody impossible. There doesn't seem to be a category to custom taxonomy converter plugin out there (the way there is for custom post type conversion,) despite the obvious need for one by anybody looking to to apply WP3.0's CMSing innovations to an already existing blog.
So I've tried going the manual route. If I manually change the "taxonomy" field of different terms in the wp_term_taxonomy table - say, from category to politicians, a custom taxonomy - all posts under that (former) category reflect the update. If you try to edit a post, the custom taxonomy meta-boxes display the right term. (I haven't tried writing a custom loop to see if the posts would display on the site, so I don't know if that works, but I assume it does.) So far, so good. OR SO IT WOULD SEEM:
The first problem is that if you go to the custom taxonomy page (the equivalent of the "category" or "post tags" page under posts,) none of the terms show up in the table at the right. If you SEARCH for them, though, they do show up.
Here is what a skilled WP developer told me when I brought this up:
"I think the problem with updating the db manually is that the post cache doesn’t get changed. (See update_post_caches().) I need to make sure I’m doing that when I change the post types, too."
Unfortunately, I'm not exactly sure what that means or what to do with that.
The second problem is that creating a custom taxonomy and associating it with posts (or any custom post type) doesn't generate a filter box on the view posts page, the way it does for categories. This makes custom taxonomies almost unusable, at least in my case.
So, does anybody have ideas on how to convert categories to custom taxonomies (or at least how to get them to display in the backend if you convert them manually) and how to add a taxonomy filter on the posts page?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在搜索了一段时间试图找到一个插件来执行此操作后,我发现可以通过批量帖子编辑器轻松完成此操作。
我刚刚在 Themespotter.com 的博客部分写下了执行此操作的步骤:
如何将帖子标签转换为 WordPress 中的自定义分类法
After searching for a while trying to find a plugin to do this, I figured out it can be done easily through the Bulk Post Editor.
I just wrote out the steps to do it on the Blog section on Themespotter.com:
How to Convert Post Tags to Custom Taxonomies in WordPress
查看这个修改后的类别/标签转换器插件
http://core.trac.wordpress.org/ticket/16460 其中包括自定义分类法。它非常适合我并且真正节省时间。
Checkout this modified category/tag converter plugin
http://core.trac.wordpress.org/ticket/16460 which includes custom taxonomies. Its working perfectly for me and a real time saver.
还有一些关于此问题的开放 WordPress 支持线程:
http://wordpress.org/support/topic/convert-tags-to -taxonomy-tags
这是一个如此明显的需求,我一直认为我一定忽略了一些基本的东西,但显然我并不孤单。
There's also some open WordPress support threads about this issue:
http://wordpress.org/support/topic/convert-tags-to-taxonomy-tags
It's such a obvious need, I keep thinking I must be overlooking something basic, but apparently I'm not alone.
我的解决方案是将标签转移、迁移、转换为多个自定义分类法。
创建自定义分类法后,运行 SQL 查询将分类法列下 wp_term_taxonomy 表内的值从“post_tag”更改为自定义分类法别名。您可以使用模式来挑选出每个类别的标签。例如,此代码将标签名称内带有“min”的所有“标准”标签传输到“length”自定义分类法:
您可以根据 这个!
在运行任何 SQL 查询之前,请务必备份数据库!
My solution was to transfer, migrate, convert... tags to multiple custom taxonomies.
After creating custom taxonomies, run SQL query to change value inside of wp_term_taxonomy table under taxonomy column from "post_tag" to a custom taxonomy slug name. You can use patterns to single out tags for each category. For example this code transfers all "standard" tags with "min" inside tag name to "length" custom taxonomy:
You can change "wildcards" according to this!
Be sure to backup your database before running any SQL query!