WPDev.one
Core Function
View Source on Trac ↗

wp_set_post_categories()

wp_set_post_categories( mixed $post_id = 0, mixed $post_categories = array(), mixed $append = false )

Sets categories for a post.

Parameters 3 required

Name / Type Description
int

$post_id Optional. The Post ID. Does not default to the ID of the global $post. Default 0.

Required
mixed

(int[] | int) $post_categories Optional. List of category IDs, or the ID of a single category. Default empty array.

Required
bool

$append If true, don't delete existing categories, just add on. If false, replace the categories with the new categories.

Required

Return Value

((array)
| false | WP_Error) Array of term taxonomy IDs of affected categories. WP_Error or false on failure.

Function Information

Since Version
2.1.0
Source File
wp-includes/post.php
Advertisement