wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_create_category › WordPress Function

Seit2.0.0
Veraltetn/v
wp_create_category ( $category_name, $category_parent = 0 )
Parameter: (2)
  • (string) $category_name Category name.
    Erforderlich: Ja
  • (int) $category_parent Optional. ID of parent category.
    Erforderlich: Nein
    Standard:
Gibt zurück:
  • (int) The ID of category term on success, or zero on failure.
Definiert in:
Codex:

Adds a new category to the database if it does not already exist.



Quellcode

function wp_create_category( $category_name, $category_parent = 0 ) {
	$id = category_exists( $category_name, $category_parent );
	if ( $id ) {
		return (int) $id;
	}

	return wp_insert_category(
		array(
			'cat_name'        => $category_name,
			'category_parent' => $category_parent,
		)
	);
}