您必须注册自定义纹理。在函数中添加以下代码。php。Ref
//hook into the init action and call create_question_taxonomies when it fires
add_action( \'init\', \'create_question_taxonomies\', 0 );
//create two taxonomies, genres and writers for the post type "question"
function create_question_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
\'name\' => _x( \'q-categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'q-category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search q-categories\' ),
\'all_items\' => __( \'All q-categories\' ),
\'parent_item\' => __( \'Parent q-categories\' ),
\'parent_item_colon\' => __( \'Parent q-categories:\' ),
\'edit_item\' => __( \'Edit q-categories\' ),
\'update_item\' => __( \'Update q-categories\' ),
\'add_new_item\' => __( \'Add New q-categories\' ),
\'new_item_name\' => __( \'New q-categories Name\' ),
\'menu_name\' => __( \'q-categories\' ),
);
register_taxonomy(\'q-categories\',array(\'question\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'q-categories\' ),
));
}
然后您只需在wp\\u insert\\u post之后添加以下代码
wp_set_post_terms( $post_id, array( \'term\', \'terms\', \'terms\' ), \'q-categories\' );