WordPress at Your Fingertips
function is not described

wp_create_categories() WP 2.0.0

Create categories for the given post.

No Hooks.

Return

Int[]. Array of IDs of categories assigned to the given post.

Usage

wp_create_categories( $categories, $post_id );
$categories(string[]) (required)
Array of category names to create.
$post_id(int)
The post ID.
Default: ''

Changelog

Since 2.0.0 Introduced.

Code of wp_create_categories() WP 5.8.2

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

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

	return $cat_ids;
}