[英]Add options to a Wordpress plugin Custom Post Type via child theme functions.php
I'm using Uncode theme for a site. 我正在为网站使用Uncode主题。 It has a core custom post type called 'portfolio'. 它具有一个称为“ portfolio”的核心自定义帖子类型。
I need to add an option to this CPT so that it shares the tags with regular posts. 我需要为此CPT添加一个选项,以便它与常规帖子共享标签。
I have found the file in the theme core where the CPT is registered and added the following and it works: 我已经在注册了CPT的主题核心中找到了该文件,并添加了以下内容并且可以正常工作:
'taxonomies' => array('portfolio_category', 'post_tag')
However, as editing core files is a big no no, I'm wondering if there is a way of doing this through my own functions file so it is future proof? 但是,由于编辑核心文件是一件很重要的事,我想知道是否有一种方法可以通过我自己的函数文件来做到这一点,所以它可以用于未来吗?
EDIT : It's apparent that I've misunderstood! 编辑 :显然我误解了!
Looks like register_taxonomy_for_object_type
is what you're after. 看起来您想要的是register_taxonomy_for_object_type
。
The WP Codex has this to say: WP法典有这样的说法:
register_taxonomy_for_object_type() register_taxonomy_for_object_type()
Add a registered Taxonomy to a registered Post Type. 将注册分类法添加到注册帖子类型。
register_taxonomy_for_object_type( 'post_tag', 'portfolio' );
Original answer: 原始答案:
From the WP Codex : 从WP Codex :
register_post_type() register_post_type()
Create or modify a post type. 创建或修改帖子类型。
register_post_type
should only be invoked through the'init'
action.register_post_type
仅应通过'init'
操作来调用。 It will not work if called before'init'
, and aspects of the newly created or modified post type will work incorrectly if called later. 如果在'init'
之前调用,它将不起作用,如果稍后调用,则新创建或修改的帖子类型的各个方面将无法正常工作。
(addtl. emphasis mine) (另外强调我的)
This being the case, you could create a function 在这种情况下,您可以创建一个函数
function igloobob_portfolio_cpt_mod() {
register_post_type('portfolio', $args);
}
add_action('init', 'igloobob_portfolio_cpt_mod', 999);
where $args
basically duplicate's the Uncode theme's arguments to register_post_type
, save for your modification. $args
基本上将Uncode主题的参数复制到register_post_type
,并保存您的修改。 The 999
priority arg is to ensure that it executes after the parent theme has already registered the post type. 999
优先级arg是为了确保它在父主题已经注册了帖子类型之后执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.