wp_insert_post via shell category not being inserted

This is typical issue. While wp_insert_post() won’t check for user capabilities to insert post, the tax_input part actually will check if user has permission to manipulate those specific taxonomies.

If you don’t have user logged in state replicated in your shell context then it will fail accordingly.

The solution is to insert post first, then assign terms via separate function calls which won’t check capabilities (yeah, it’s not consistent).

tech