wp_set_post_categories
wp_set_post_categories ( $post_id = 0, $post_categories = array(), $append = false )
Parameters:- (int) post_id Optional. The Post ID. Does not default to the ID of the global $post. Default 0.
- (int[]|int) post_categories Optional. List of category IDs, or the ID of a single category. Default empty array.
- (bool) append If true, don't delete existing categories, just add on. If false, replace the categories with the new categories.
Returns:- (array|false|WP_Error) Array of term taxonomy IDs of affected categories. WP_Error or false on failure.
Defined at: - Introduced in WordPress: 2.1.0
- Deprecated in WordPress: —
Description
Sets categories for a post.If no categories are provided, the default category is used.