无法将自定义分类添加到自定义发布类型

时间:2014-07-11 作者:Shah

我无法将分类添加到自定义帖子类型。但对于相同的代码,如果我添加“post”或“page”,它会显示得很好。我无法指出问题所在。

这是代码。

注册自定义职位类型-工作正常

register\\u taxonomy($键,\'SH\\u job\\u listings\',$值)如果我用帖子或页面替换“SH\\u job\\u listings”,效果很好,但不适用于我创建的自定义帖子类型。

class SH_job_post_class{

    public function  __construct(){
        $this->register_job_Listings();
        $this->add_taxonomies();

    }

    public function register_job_Listings(){
        $args = array(
            \'labels\' => array(
                \'name\' => \'Job Listings\',
                \'singular_name\' => \'job Listing\',
                \'add_new\' => \'Add New Job\',
                \'add_new_item\' => \'Add New Job\',
                \'edit_item\' => \'Edit Jobs\',
                \'new_item\' => \'New Item\',
                \'view_item\' => \'View Item\',
                \'search_item\' => \'Search Jobs\',
                \'not_found\' => \'No Job Found\',
                \'not_found_in_trash\' => \'No Job Found In Trash\'
            ),
            \'query_var\' => \'job\',
            \'rewrite\' => array(
                \'slug\' => \'jobs/\'
            ),
            \'public\' => true,
            \'menu_position\' => 5,
            //\'menu_icon\' => admin_url().
            \'supports\' => array(
                \'title\',
                \'thumbnail\',
                \'editor\',
                \'custom_fields\'
            )
        );

        // This function is actually registering post type
        register_post_type(\'SH_job_listings\', $args);
    }

    public function add_taxonomies(){
        $taxonomies = array();

        $taxonomies[\'job\'] = array(
            \'hierarchical\' => true,
            \'show_ui\'  => true,
            \'show_admin_column\'=> true,
            \'query_var\' => \'job_type\',
            \'rewrite\' => array(
                \'slug\' => \'job/job_type\'
            ),
            \'labels\' => array(
                \'name\' => \'job type\',
                \'singular_name\' => \'Job Type\',
                \'edit_item\' => \'Edit Job Type\',
                \'update_item\' => \'Update Job Type\',
                \'add_new_item\' => \'Add  Job Type\',
                \'new_item_name\' => \'New Job Type\',
                \'all_items\' => \'All Job\',
                \'popular_items\' => \'Popular Job Types\',
                \'search_items\' => \'Search Job Types\',
                \'separate_items_with_commas\' => \'Separate Job Types with commas \',
                \'add_or_remove_items\' => \'Add or Remove Job Type\',
                \'choose_from_most_used\' => \'Choose from most used Job Type\'

            )
        );
        $this->register_all_taxonomy($taxonomies);

    }
    public function register_all_taxonomy($all_taxonomy){

        foreach($all_taxonomy as $key => $value){
            register_taxonomy($key, \'SH_job_listings\', $value);
        }

    }

}

add_action(\'init\', function(){
    new SH_job_post_class();
});

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

请注意两者的参数规则register_post_type:

$post\\u类型(字符串)(必需)post类型。(最多20个字符,can not contain capital letters 或空间)

register_taxonomy:

$分类法(字符串)(必需)分类法的名称。Name should only contain lowercase letters 和下划线字符,且长度不超过32个字符(数据库结构限制)

结束

相关推荐

How can I find plugins' slug?

我想知道如何才能找到插件的slug(slug=WordPress用来更新插件和确定哪些插件当前处于活动状态的内部名称)?它通常是插件的文件夹名,但如果插件没有文件夹,则是其文件名(如hello.php)。是否有其他例外情况?大小写字符重要吗</插件的slug是否可以与其文件夹名不同?如果有一个叫做hello的插件呢。php和另一个/您好。php/您好。php