wp_insert_post breaks rewrite rules

Hard to say what your issue is without seeing more code, but I would bet that your issue will be resolved if you add this after inserting your post:

do_action('save_post', $post_ID, $post);

WordPress uses this action to flush cache, rewrite rules, etc. Make sure to use the appropriate variables for $post_ID and $post, of course. For good measure, you should also add:

do_action('wp_insert_post', $post_ID, $post);

Just so any plugins, themes, etc. which use this hook will know to do whatever it is they do.

Cheers~

Leave a Comment