# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/post-types/restricting-results-by-user-groups-using-the-groups-plugin-by-itthinx.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
