wp_create_categories( string[] $categories, int $post_id = '' )
Create categories for the given post.
Description Description
Parameters Parameters
- $categories
-
(string[]) (Required) Array of category names to create.
- $post_id
-
(int) (Optional) The post ID.
Default value: ''
Return Return
(array) List of categories to create for the given post.
Source Source
File: wp-admin/includes/taxonomy.php
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | 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 ; } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |