Restricting results by user Groups using the Groups plugin by itthinx
To restrict the plugin search results by user groups, when using the Groups plugin, please use the custom code below.
1
add_filter('asp_results', 'asp_fix_groups_exclusions', 10, 1);
2
function asp_fix_groups_exclusions($results) {
3
// Group based exclusions
4
if ( class_exists('Groups_Post_Access') ) {
5
foreach ($results as $k => &$r) {
6
if ( isset($r->post_type) && !Groups_Post_Access::user_can_read_post($r->id) )
7
unset($results[$k]);
8
}
9
}
10
// Category based exclusions
11
if ( class_exists('Groups_Restrict_Categories') ) {
12
foreach ($results as $k => &$r) {
13
if ( isset($r->post_type) && !Groups_Restrict_Categories::user_can_read($r->id) )
14
unset($results[$k]);
15
}
16
}
17
return $results;
18
}
Copied!
Please note, that this may affect the number of results returned negatively, as this code will remove the unwanted results from the list during the results post processing.
Last modified 1yr ago
Copy link