Un motore di ricerca WordPress per sviluppatori e autori di temi



wp_create_categories ›

Da2.0.0
Deprecaton/a
wp_create_categories ( $categories, $post_id = '' )
Parametri: (2)
  • (string[]) $categories Array of category names to create.
    Richiesto:
  • (int) $post_id Optional. The post ID. Default empty.
    Richiesto: No
    Default: (vuoto)
Ritorna:
  • (array) List of categories to create for the given post.
Definito a:
Codex:

Create categories for the given post.



Sorgenti

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;
}