Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Excluding a specific role from the search? › Reply To: Excluding a specific role from the search?
November 25, 2020 at 2:56 pm
#30362
Keymaster
Hi,
Well, probably, but only in post process. I recommend the asp_results hook for that. Maybe this custom code would work:
add_action("asp_results", "asp_exclude_by_role");
function asp_exclude_by_role($results) {
$exclude_role = 'role_name';
foreach ( $results as $k => &$r ) {
if ( isset($r->post_type) && in_array( $exclude_role, ( new WP_User( $r->author ) )->roles ) ) {
unset($results[$k]);
}
}
return $results;
}