> For the complete documentation index, see [llms.txt](https://knowledgebase.ajaxsearchpro.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.ajaxsearchpro.com/miscellaneous/post-types/restricting-results-by-user-groups-using-the-groups-plugin-by-itthinx.md).

# Restricting results by user Groups using the Groups plugin by itthinx

&#x20;To restrict the plugin search results by user groups, when using the [Groups plugin](https://hu.wordpress.org/plugins/groups/), please use the custom code below.

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

```php
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;
}
```

{% hint style="warning" %}
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.
{% endhint %}
