WordPress preview URL of Draft or pending post

i have a problem with the preview link, generated for a post with the post-status “draft”. I guess “pending” is the same.
There is a permastructure defined like this:

add_permastruct('post-type-name', '/page-name/%post-type-name%', array(
    'with_front' => false,
    'walk_dirs' => false
));

When i click on Preview for a post with post status “published” it redirects to http://domain-name.dev/wordpress/page-name/post-type-name/. That’s fine.

Read More

When i click on Preview for a post with post status “draft” it redirects to http://domain-name.dev/wordpress/?p=12345&post_type=post-type-name&preview_id=12345&preview=true&preview_nonce=123nonce45. Permastructure is not applied.

WordPress Version 4. Installed in a sub directory called “wordpress”.

htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

Any Ideas?

Also tested with a fresh WP 4 installation in root folder, without any plugins or custom post-types. Quite the same.

Thanks for helping me out.
Cheers from Berlin
christoph

Related posts

Leave a Reply

1 comment

  1. Those who still having this problem.

    I had this problem but it derived by my custom rewrite_rule.
    I have solved it by modifying the get_preview_post_link args

    add_filter( 'preview_post_link', 'custom_preview_post_link', 10, 2 );
    
    function custom_preview_post_link( $link, WP_Post $post )
    {
    //    if ($post->post_status != 'publish') {
             return remove_query_arg( 'preview_id', $link );
    //    }
    };
    

    NOTE: I have added a condition to check the post_status != ‘publish’ inside the function alter_normal_post_link() and it will be called here add_filter(‘post_link’, ‘alter_normal_post_link’, 10, 3);

    This may not answer your problem but just give you an idea.