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

This topic contains 2 replies, has 2 voices, and was last updated by GenusWeb GenusWeb 3 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22800
    GenusWeb
    GenusWeb
    Participant

    Hi,

    I am using the Plugin Groups by Itthinx to filter who are able to see some of the posts. Using the plugin, I can filter posts which can be viewed by only a certain group of users that I have set. It works properly with WordPress’ default search. However, when using Ajax Search Pro, any filtered posts by Groups Plugin do not appear on the Ajax Search Pro search results. Please see attachment for a screenshot of the issue.

    Attachments:
    You must be logged in to view attached files.
    #22814
    Ernest Marcinko
    Ernest 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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #22834
    GenusWeb
    GenusWeb
    Participant

    Thanks! For some unknown reason, it works now.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.