0

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?

1

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'));
        }
    }
}
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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