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



wp_create_categories › WordPress Function

Od2.0.0
Przestarzałyn/a
wp_create_categories ( $categories, $post_id = '' )
Parametry: (2)
  • (string[]) $categories Array of category names to create.
    Wymagane: Tak
  • (int) $post_id Optional. The post ID. Default empty.
    Wymagane: Nie
    Domyślny: (puste)
Powrót:
  • (int[]) Array of IDs of categories assigned to the given post.
Zdefiniowane na:
Codex:

Creates categories for the given post.



Źródło

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