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.

What is this, and where do I put this custom code?

add_filter('asp_results', 'asp_fix_groups_exclusions', 10, 1);
function asp_fix_groups_exclusions($results) {
	// Group based exclusions
	if ( class_exists('Groups_Post_Access') ) {
		foreach ($results as $k => &$r) {
			if ( isset($r->post_type) && !Groups_Post_Access::user_can_read_post($r->id) )
				unset($results[$k]);
		}
	}
	// Category based exclusions
	if ( class_exists('Groups_Restrict_Categories') ) {
		foreach ($results as $k => &$r) {
			if ( isset($r->post_type) && !Groups_Restrict_Categories::user_can_read($r->id) )
				unset($results[$k]);
		}
	}
	return $results;
}

Last updated