I'm creating a system, where some custom post drafts are being prepared, and after certain actions taken by moderators it is being automatically published.
So, first I create post draft like that:
$newpost = array( 'post_title' => 'Raport '.date("Y-m-d"), 'post_content' => 'Add your content here', 'post_type' => 'raport', 'post_status' => 'draft', 'post_author' => $userid ); wp_insert_post($newpost);
This draft awaits for admins to take some action. It can be edited etc., and on edit page the permalink designed for this post is OK.
After admins perform certain actions, the system publishes the post automatically:
But after that the post's permalink is being broken. Instead of standard permalink (that wa visible on edit page):
the post's permalink after
wp_publish_post looks like that:
which directs to custom post's type archive page, not to the post itself.
How can I fix it and publish these posts without breaking the permalinks?