wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



wp_create_category › WordPress Function

Od2.0.0
Przestarzałyn/a
› wp_create_category ( $category_name, $category_parent = 0 )
Parametry: (2)
  • (string) $category_name Category name.
    Wymagane: Tak
  • (int) $category_parent Optional. ID of parent category.
    Wymagane: Nie
    Domyślny: —
Powrót:
  • (int) The ID of category term on success, or zero on failure.
Zdefiniowane na:
Codex:

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



Źródło

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