wp_create_categories( array $categories, int $post_id = '' )

Create categories for the given post.


Parameters

$categories

(Required) List of categories to create.

$post_id

(Optional) The post ID.

Default value: ''


Return

(array) List of categories to create for the given post.


Source

File: wp-admin/includes/taxonomy.php

function wp_create_categories( $categories, $post_id = '' ) {
	$cat_ids = array ();
	foreach ( $categories as $category ) {
		if ( $id = category_exists( $category ) ) {
			$cat_ids[] = $id;
		} elseif ( $id = wp_create_category( $category ) ) {
			$cat_ids[] = $id;
		}
	}

	if ( $post_id )
		wp_set_post_categories($post_id, $cat_ids);

	return $cat_ids;
}


Changelog

Changelog
Version Description
WP-2.0.0 Introduced.