重复我的评论(CPT and Taxonomies connection), 您需要通过register_post_type
功能如下:
<?php
function add_post_type($name, $args = array()) {
add_action(\'init\', function() use($name, $args) {
$upper = ucwords($name);
$name = strtolower(str_replace(\' \',\'_\',$name));
$args = array_merge(
array(
\'public\'=> true,
\'label\' => "All $upper" . \'s\',
\'labels\' => array(\'add_new_item\' => "Add New $upper"),
\'support\' => array(\'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\'),
//Add the taxonomy "fun" to this post type
\'taxonomies\' => array(\'fun\'),
),
$args
);
//Remove quotes from the $name variable
register_post_type($name, $args);
});
}
function add_taxonomy($name, $post_type, $args = array()) {
$name = strtolower($name);
add_action(\'init\', function() use($name, $post_type, $args) {
$args = array_merge(
array(
\'label\' => ucwords($name),
),
$args
);
register_taxonomy($name, $post_type, $args);
});
}
add_post_type(\'book\', array(
\'supports\' => array(\'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\')
));
add_taxonomy(\'fun\', \'book\');