This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Restrict search results to roles

#49256
Ernest MarcinkoErnest Marcinko
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.