Private Posts/Pages & Search

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?

Related posts

1 comment

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

Comments are closed.