1

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 Answer 1

2

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')); } } } 
8
  • 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. Commented Aug 18, 2013 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. Commented Aug 18, 2013 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! Commented Aug 18, 2013 at 20:20
  • Ah, I see, you should be able to include the additional post statuses as an array then. array('private','public') Commented Aug 18, 2013 at 22:48
  • 1
    it's 'publish' not 'public' Commented Aug 19, 2013 at 2:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.