Filter posts (or CPT) which user can’t access
The only way of checking and filtering the posts not accessible by the current user is during the post processing of the search results.
1
add_filter( 'asp_results', 'asp_filter_posts_by_capability', 10, 1 );
2
function asp_filter_posts_by_capability( $results ) {
3
foreach ($results as $k => &$r ) {
4
if ( !current_user_can('read_post', $r->id) )
5
unset($results[$k]);
6
}
7
return $results;
8
}
Copied!
Last modified 1yr ago
Copy link