wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_create_category › WordPress Function

Depuis2.0.0
Dépréciéen/a
wp_create_category ( $cat_name, $category_parent = 0 )
Paramètres: (2)
  • (int|string) $cat_name Category name.
    Requis: Oui
  • (int) $category_parent Optional. ID of parent category.
    Requis: Non
    Défaut:
Retourne:
  • (int|WP_Error)
Défini(e) dans:
Codex:

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



Source

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

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