How to insert category and subcategory using ‘wp_insert_post’ function?
The argument description in the Codex entry for wp_insert_post() has exactly what you need (reformatted). ‘post_category’ => [ array(<category id>, <…>) ] //post_category no longer exists, try wp_set_post_terms() for setting a post’s categories So, per the Codex. Use wp_set_post_terms(). wp_set_post_terms( $post_id, array( 1, 2, 3), ‘category’, true ); For custom taxonomies: ‘tax_input’ => array( ‘taxonomy_name’ … Read more