Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a site up where there is one private page and one private post. When logged is as admin, i can view both of these, and they even appear in the search.

However, when logged in as an editor, I can still see the posts, but they don't appear in the search. I found this a bit strange, was wondering if anyone has experienced this or knows how to make the private pages and posts appear in the search when logged in as an editor?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

This is the default WordPress behavior.

http://codex.wordpress.org/Content_Visibility#Private_Content

Private posts are automatically published but not visible to anyone but those with the appropriate permission levels (Editor or Administrator).

WARNING: If your site has multiple editors or administrators, they will be able to see your protected and private posts in the Edit panel.

If you want to show private posts on the front-end of the site to logged-in editors you can add this code to functions.php.

add_action('pre_get_posts','filter_search');
function filter_Search($query){
    if( is_admin() || ! $query->is_main_query() ) return;
    if ($query->is_search) {
        if( current_user_can('edit_private_posts') ) {
            $query->set('post_status',array('private','publish'));
        }
    }
}
share|improve this answer
    
Im fully aware of that. " wondering if anyone has experienced this or knows how to make the private pages and posts appear in the search when logged in as an editor". what i am asking is: if both user roles can see the posts, why do the private posts only appear in a search when logged in as admin and not editor. –  RoseCoder Aug 18 '13 at 18:33
    
@RoseCoder Sorry, I missed part of your question. I've updated my response with a solution for showing private posts in the search. –  epilektric Aug 18 '13 at 18:58
    
No worries dude, thanks for the answer - i tried the code in my functions file, but it now only returns private posts only and no public ones! –  RoseCoder Aug 18 '13 at 20:20
    
Ah, I see, you should be able to include the additional post statuses as an array then. array('private','public') –  epilektric Aug 18 '13 at 22:48
1  
it's 'publish' not 'public' –  Jesse Aug 19 '13 at 2:18
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.