1
votes

i'm developing a web portal using wordpress.

I need to access draft posts from frontend. If i login with administrator account i can view draft posts(admins posts) in single pages. But other users can't access their own drafts from frontend and gets 404 error.

The links on frontpage like http://website.com/?p=486

I'm not sure whats the problem about. Maybe access restrictions or permalink settings or 404 settings or something else. Any ideas?

2

2 Answers

0
votes

I found the solution. The problem is single page only shows published posts. With using wordpress pre_get_posts hook i changed the query and add also draft posts.

function ceo_single_page_published_and_draft_posts( $query ) {
    if( is_single() ) {
        $query->set('post_status', 'publish,draft');
    }
}
add_action('pre_get_posts', 'ceo_single_page_published_and_draft_posts');
0
votes

The solution that works for me is to query for published and draft:

        query_posts(array(
            'post_status' => array( 'publish', 'draft')
        ));