Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Ultimate Member and Ajax Search Pro › Reply To: Ultimate Member and Ajax Search Pro
July 13, 2020 at 1:59 pm
#28419
Keymaster
Sure, this is very helful. Based on their suggestion, this should do it:
add_filter( 'asp_results', 'asp_filter_posts_by_capability', 10, 1 );
function asp_filter_posts_by_capability( $results ) {
foreach ($results as $k => &$r ) {
if ( $r->content_type == 'pagepost' && !asp_um_has_access($r->id) ) {
unset($results[$k]);
}
}
return $results;
}
function asp_um_has_access($post_id) {
$access = true;
$restriction = get_post_meta( $post_id, 'um_content_restriction', true ); //This array contains all content restriction settings
if ( isset($restriction['_um_access_roles']) ) { //this gives the array of restricted roles
$access = UM()->Access()->user_can( get_current_user_id(), $restriction['_um_access_roles'] );
}
return $access;
}