使用REGISTER_TASTIONY更新分类的插件的正确方法是什么?

时间:2015-02-16 作者:Shawn

更新插件注册的自定义分类法的slug的最佳方法是什么?我想知道这个参数的最小数量,或者我是否需要复制粘贴所有原始参数。如果插件有更新,这似乎很容易出错。codex说,使用register\\u分类法时,您将覆盖原始分类法,那么有更好的方法来实现这一点还是其他功能?

1 个回复
最合适的回答,由SO网友:Milo 整理而成

register_taxonomy 触发操作registered_taxonomy 在它注册之后,它会立即提供它注册时使用的参数。只要分类键不变,就可以挂接该操作,修改参数,然后重新注册它。

function wpd_update_taxonomy_args( $taxonomy, $object_type, $args ){
    if( \'plugin_tax\' == $taxonomy ){

        // remove this action so we don\'t create an infinite loop!
        remove_action( current_action(), __FUNCTION__ );

        // change arguments
        $args[\'rewrite\'] = array( \'slug\' => \'foobar\' );

        // re-register
        register_taxonomy( $taxonomy, $object_type, $args );
    }
}
add_action( \'registered_taxonomy\', \'wpd_update_taxonomy_args\', 10, 3 );

结束

相关推荐

Get taxonomy names by post id

我试图创建一个页面,在其中一个页面上显示几个帖子。到目前为止还不错。一切正常。现在,我在foreach循环中显示帖子,检查它们是否连接到页面。我需要的是wp_get_post_terms($post->ID); 但这行不通。有custom registered_taxonomy\'s那么我怎样才能得到所有taxonomy names 通过$post->ID?