Just to clarify – the two posts (one published and one draft) are separate posts with their own slugs (but the draft has a “-2” at the end of the slug), but have the same post title.
I would like to reproduce your issue but whenever I am publishing a post from draft, I am not been able to keep the draft version. How are you doing this? How are you keeping both draft and published version of the same post?
When a published post is reverted back to Draft status WordPress won’t allow a visitor to see the content of that post any more.
I don’t think there is anything wrong in the code. Can you try to print the post ID on single.php and check what exactly you are getting? Also what var_dump says?
In the plugin code if you are usingWP_Query, please make sure you have used status=>'publish'.
If you have other plugins installed in your application, before doing anything else, please deactivate them all and see if the issue still persists. If no, find out the actual plugin by activating plugins one by one and checking whether the issue comes up due to the latest plugin activated.
Hmm, Separate Posts! That’s what I thought. Anyway, I created two separate posts with same title. Now I have two almost similar permalinks with the difference of having “-2” at the end in one of these two.
But for me single.php page loads only the published post, as it should be. Also when they are separate posts, there is no way of getting a conflict as those two have completely separate post ID.
I think you need to look into your plugin code where you are running a query (probably) to fetch the list of posts.
Hi – I appreciate your response. What is the proper way to link to a specific post from a listing of posts? Here is the code I used:
<?php $args = array(
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args );
foreach ( $posts_array as $post ) : setup_postdata( $post );
?>
<a href="<?php echo the_permalink();?>" class="underline"><?php echo the_title();?></a>
<?php
endforeach;
Your query code is fine. I think what Subrata is suggesting is some plugin code is altering post queries, causing drafts to be included in queries. This is easily done through the pre_get_posts action by adding ‘draft’ to the ‘post_status’ query var. If you were to disable all plugins, I think you will find that drafts are no longer included. If you re-activate your plugins one by one, once drafts reappear, the last activated plugin is the one adding ‘draft’ to query vars.