This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Ajax Search Pro Does Not Include posts which are filtered by Groups Plugin

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Ajax Search Pro Does Not Include posts which are filtered by Groups Plugin Reply To: Ajax Search Pro Does Not Include posts which are filtered by Groups Plugin

#22814
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

I recall someone having a similar issue with that plugin. We resolved it by suggesting a custom code to exclude the posts that users have no access to. In your case it looks different. I think your search configuration might be incorrect somewhere. If you choose the correct post types, it should return everything, including the ones restricted from the current user. Please check your search configuration. Once you got that, then try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

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