我无法将分类添加到自定义帖子类型。但对于相同的代码,如果我添加“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();
});