您注册分类法的方式似乎有问题。我宁愿先注册分类法,然后再注册post类型。
我提交了一个拉拽请求,但你看:
<?php
// hook into the init action and call create_book_taxonomies when it fires
add_action( \'init\', \'create_ksasexhibits_taxonomies\', 0 );
// create two taxonomies, genres and writers for the post type "book"
function create_ksasexhibits_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
\'name\' => _x( \'Exhibition Types\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Exhibition Type\', \'taxonomy singular name\' ),
\'add_new\' => _x( \'Add New Exhibition Type\', \'Exhibition Type\'),
\'add_new_item\' => __( \'Add New Exhibition Type\' ),
\'edit_item\' => __( \'Edit Exhibition Type\' ),
\'new_item\' => __( \'New Exhibition Type\' ),
\'view_item\' => __( \'View Exhibition Type\' ),
\'search_items\' => __( \'Search Exhibition Types\' ),
\'not_found\' => __( \'No Exhibition Type found\' ),
\'not_found_in_trash\' => __( \'No Exhibition Type found in Trash\' ),
);
$args = array(
\'labels\' => $labels,
\'singular_label\' => __(\'Exhibiton Type\'),
\'public\' => true,
\'show_ui\' => true,
\'hierarchical\' => true,
\'show_tagcloud\' => false,
\'show_in_nav_menus\' => false,
\'rewrite\' => array(\'slug\' => \'exhibiton\', \'with_front\' => false ),
);
register_taxonomy( \'exhibition_type\', \'ksasexhibits\', $args );
}
function register_ksasexhibits_posttype() {
$labels = array(
\'name\' => _x( \'Exhibits & Programs\', \'post type general name\' ),
\'singular_name\' => _x( \'Exhibit\', \'post type singular name\' ),
\'add_new\' => __( \'Add New Exhibit & Program\' ),
\'add_new_item\' => __( \'Add New Exhibit & Program\' ),
\'edit_item\' => __( \'Edit Exhibit & Program\' ),
\'new_item\' => __( \'New Exhibit & Program\' ),
\'view_item\' => __( \'View Exhibit & Program\' ),
\'search_items\' => __( \'Search Exhibit & Program\' ),
\'not_found\' => __( \'No Exhibit & Program found\' ),
\'not_found_in_trash\'=> __( \'No Exhibit & Program found in Trash\' ),
\'parent_item_colon\' => __( \'\' ),
\'menu_name\' => __( \'Exhibits & Programs\' )
);
//$taxonomies = array( \'exhibition_type\' );
$supports = array(\'title\',\'revisions\',\'thumbnail\' );
$post_type_args = array(
\'labels\' => $labels,
\'singular_label\' => __(\'Exhibit & Program\'),
\'public\' => true,
\'show_ui\' => true,
\'publicly_queryable\'=> true,
\'query_var\' => true,
\'capability_type\' => \'post\',
\'has_archive\' => false,
\'hierarchical\' => true,
\'rewrite\' => array(\'slug\' => \'exhibitons\', \'with_front\' => false ),
\'supports\' => $supports,
\'menu_position\' => 5,
//\'taxonomies\' => $taxonomies,
\'show_in_nav_menus\' => true
);
register_post_type(\'ksasexhibits\',$post_type_args);
}
add_action(\'init\', \'register_ksasexhibits_posttype\');
function define_exhibiton_type_terms() {
$terms = array(
\'0\' => array( \'name\' => \'Campus Partnerships\',\'slug\' => \'campus\'),
\'1\' => array( \'name\' => \'Community Partnerships\',\'slug\' => \'community\'),
\'2\' => array( \'name\' => \'Independent Study\',\'slug\' => \'independent\'),
\'3\' => array( \'name\' => \'Digital Work.\',\'slug\' => \'digital\'),
\'4\' => array( \'name\' => \'Mellon Foundation\',\'slug\' => \'mellon\'),
);
return $terms;
}
function check_exhibition_type_terms(){
//see if we already have populated any terms
$terms = get_terms (\'exhibition_type\', array( \'hide_empty\' => false ) );
//if no terms then lets add our terms
if( empty( $terms ) ){
$terms = array(
\'0\' => array( \'name\' => \'Campus Partnerships\',\'slug\' => \'campus\'),
\'1\' => array( \'name\' => \'Community Partnerships\',\'slug\' => \'community\'),
\'2\' => array( \'name\' => \'Independent Study\',\'slug\' => \'independent\'),
\'3\' => array( \'name\' => \'Digital Work.\',\'slug\' => \'digital\'),
\'4\' => array( \'name\' => \'Mellon Foundation\',\'slug\' => \'mellon\'),
);
foreach( $terms as $term ){
if( !term_exists( $term[\'name\'], \'exhibition_type\' ) ){
wp_insert_term( $term[\'name\'], \'exhibition_type\', array( \'slug\' => $term[\'slug\'] ) );
}
}
}
}
add_action ( \'init\', \'check_exhibition_type_terms\' );
?>