为什么WordPress的分类法没有注册?

时间:2017-03-01 作者:plaidmelon

我正在尝试创建附加到自定义帖子类型的分类法。CPT的注册情况良好,但分类法没有显示出来。最终会有多种分类法。

我没有看到任何错误(没有致命的WP错误,浏览器控制台中没有任何错误),但WP没有注册分类法。分类法类似乎根本就不存在。我在WP外部进行了检查,以查看是否所有值都存在,并且它们似乎被正确传递。

为什么不注册?感谢您的指导,代码如下。。。

class pm_createTaxonomy
{
protected $textdomain;

public function __construct($textdomain)
{
    $this -> textdomain = $textdomain;

    add_action(\'init\', array($this, \'registerTaxonomy\'));
}

public function makeTaxonomy($taxName, $singularName, $pluralName, $postTypes, $settings=array())
{
    /* Cleanup slugs just in case */
    $this -> taxName = strtolower(str_replace(\' \', \'_\', $taxName));
    $this -> postTypes = $postTypes;

    /* Default labels */
    $default_labels = array(
        \'name\'                       => __($pluralName, $this->textdomain),
        \'singular_name\'              => __($singularName, $this->textdomain),
        \'search_items\'               => __(\'Search \' . strtolower($pluralName), $this->textdomain),
        \'poular_items\'               => __(\'Popular \' . strtolower($pluralName), $this->textdomain),
        \'choose_from_most_used\'      => __(\'Choose from most used \' . strtolower($pluralName), $this->textdomain),
        \'all_items\'                  => __(\'All \' . strtolower($pluralName), $this->textdomain),
        \'parent_item\'                => __(\'Parent \' . $singularName, $this->textdomain),
        \'parent_item_colon\'          => __(\'Parent \' . $singularName, $this->textdomain),
        \'edit_item\'                  => __(\'Edit \' . $singularName, $this->textdomain),
        \'update_item\'                => __(\'Update \' . $singularName, $this->textdomain),
        \'add_new_item\'               => __(\'Add New \' . $singularName, $this->textdomain),
        \'new_item_name\'              => __(\'New \' . $singularName, $this->textdomain),
        \'add_or_remove_items\'        => __(\'Add or remove \' . strtolower($pluralName), $this->textdomain),
        \'menu_name\'                  => __($pluralName, $this->textdomain),
        \'separate_items_with_commas\' => __(\'Separate \' . strtolower($pluralName) . \' with commas\', $this->textdomain)
    );

    $default_args = array(
        \'hierarchical\'      => true,
        \'label\'             => $pluralName,
        \'labels\'            => $default_labels,
        \'public\'            => true,
        \'show_admin_column\' => true,
        \'show_ui\'           => true,
        \'show_in_nav_menus\' => true,
        \'rewrite\'           => array(\'slug\' => sanitize_title_with_dashes($pluralName)),
    );

    $this -> args = array_merge($default_args, $settings);
}

public function registerTaxonomy()
{
    register_taxonomy($this->taxName, $this->postTypes, $this->args);
}

}

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

今晚又做了一些工作,重播了一些东西。编辑上面的代码以反映更改,现在一切正常。将标记为已解决。

相关推荐

如何控制根据Taxonomy术语显示什么模板?

我正在建立一个商业目录,并将给出一些背景,然后在最后有2个问题。The development URL is: http://svcta.lainternet.biz/The website I am rebuilding is: https://www.visitsimivalley.com/当前网站要求每个分类法类型具有唯一的业务概要文件。例如,如果您是一家酒店,并且您也有会议室和婚礼场地,那么您最终会得到3个列表,一个用于酒店,一个用于会议,一个用于婚礼。我希望有一个主配置文件,其中包含我们将显示的