Show Post in Draft status with permalinks /% postname% / in WordPress

0

Greetings Community, I want to show comments with the template single.php having the permalink /% postname% / since the published posts remain with the assigned name but when wanting to display the post with draft status, does it generate the URL? post_type = comments & p = 1736 a 404 error, is it possible to show this type of post in another way?

A thousand thanks.

    
asked by pio 08.09.2016 в 22:19
source

1 answer

0

The %postname% corresponds to the field post_slug of the table wp_posts and this field is calculated with the function wp_unique_post_slug() when you change the status to published .

In this answer propose this Function:

global $post;
if (in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
    $my_post = clone $post;
    $my_post->post_status = 'published';
    $my_post->post_name = sanitize_title($my_post->post_name ? $my_post->post_name : $my_post->post_title, $my_post->ID);
    $permalink = get_permalink($my_post);
} else {
    $permalink = get_permalink();
}

This function can be placed in your file functions.php following a tutorial like this .

    
answered by 09.09.2016 в 02:57