Skip to content

Instantly share code, notes, and snippets.

@i-Captain
Last active June 28, 2018 13:13
Show Gist options
  • Select an option

  • Save i-Captain/63f322598d983c91536dd6a47a649016 to your computer and use it in GitHub Desktop.

Select an option

Save i-Captain/63f322598d983c91536dd6a47a649016 to your computer and use it in GitHub Desktop.
Wordpress - Search private posts
<?php
// SEARCH PRIVATE POSTS
// https://wordpress.stackexchange.com/questions/110569/private-posts-pages-search
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'));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment