Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Restrict search results to roles › Reply To: Restrict search results to roles
September 12, 2024 at 9:40 am
#49256
Keymaster
Hi!
It is very likely possible, but some custom code will be required, depending on how these roles are set. I found a previous topic, where someone else had a similar request, and this custom code was suggested:
add_filter( 'asp_results', 'asp_filter_posts_by_capability', 10, 1 );
function asp_filter_posts_by_capability( $results ) {
foreach ($results as $k => &$r ) {
if ( !current_user_can('read_post', $r->id) )
unset($results[$k]);
}
return $results;
}
This however may need to be edited with the correct capability or a function to check if the user is a customer.