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


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: wp_publish_post($id);.

But after that the post's permalink is being broken. Instead of standard permalink (that was 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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.