wp_create_categories() – Create categories for the given post.
You appear to be a bot. Output may be restricted
Description
Create categories for the given post.
Usage
$int[] = wp_create_categories( $categories, $post_id );
Parameters
- $categories
- ( string[] ) required – Array of category names to create.
- $post_id
- ( int ) optional – Optional. The post ID. Default empty.
Returns
int[] Array of IDs of categories assigned to the given post.
Source
File name: wordpress/wp-admin/includes/taxonomy.php
Lines:
1 to 20 of 20
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; }