我正在尝试创建附加到自定义帖子类型的分类法。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);
}
}