在 WordPress 中,您如何在代码中使用自定义帖子类型注册内置分类法? [英] In WordPress how do you register built-in taxonomies with custom post types in code?

查看:22
本文介绍了在 WordPress 中,您如何在代码中使用自定义帖子类型注册内置分类法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WordPress codex 有很多关于如何使用自定义帖子类型注册自定义分类法的示例,但我找不到太多关于将内置分类法(标签和类别)与 cpt 结合使用的信息.

The WordPress codex has a lot of examples of how to register custom taxonomies with custom post types, but I couldn't find much about using built-in taxonomies (tags & categories) with cpts.

我有一个名为listings的cpt,我需要在listing cpt页面中添加标准的category和tag UI元素.我还需要使用我的functions.php 中的代码来执行此操作,而不是使用插件.

I have a cpt called listings, and I need to add the standard category and tag UI elements to the listing cpt page. I also need to do this with code in my functions.php, rather than using a plugin.

推荐答案

完全不是问题.当您注册帖子类型时,只需将此参数添加到数组中即可:

Not a problem at all. When you register the post type, just add this argument to the array:

'taxonomies' => array( 'category', 'post_tag' )

这篇关于在 WordPress 中,您如何在代码中使用自定义帖子类型注册内置分类法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆