Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Filter search results based on authentication status
This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko 2 years, 9 months ago.
- AuthorPosts
- August 14, 2020 at 12:34 am #28928
Hello
I’m just wondering if it’s possible to remove search results containing restricted content if the person performing the search is not authenticated.
I found this support article, which indicates yes, you can remove restricted content from search results. However we are using MemberPress, and have Apache Solr as our search backend.
In my testing, our search results currently contain content from all pages/posts, regardless of authentication status. Can we use the code snippet from the link above to protect MemberPress-controlled content?
Thanks!
August 14, 2020 at 9:17 am #28938Hi,
It should be possible, but a API method is required from the other plugin. The best would be a function that can check if the current user has access to a post by it’s ID.
Best,
Let me know if there is any method in memberpress, and I can help you with the implementation.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
August 17, 2020 at 7:45 pm #29018He Ernest
MemberPress support suggested trying
MeprRule::is_locked($r)
function asp_fix_groups_exclusions($results) { // Group based exclusions if ( class_exists('MeprRule') ) { foreach ($results as $k => &$r) { if ( isset($r->post_type) && MeprRule::is_locked($r) ) unset($results[$k]); } } return $results; } add_filter('asp_results', 'asp_fix_groups_exclusions', 10, 1);
This had no effect, all results were returned to all users. Do you see any issues with the code? This was placed in a child theme’s functions.php.
Thanks
August 18, 2020 at 10:03 am #29029Hi,
That looks almost all right, but the $r variable in that case does not contain a post object, so this should be it:
Best,add_filter('asp_results', 'asp_fix_groups_exclusions', 10, 1); function asp_fix_groups_exclusions($results) { // Group based exclusions if ( class_exists('MeprRule') ) { foreach ($results as $k => &$r) { if ( isset($r->post_type) ) { $post = get_post( $r->id ); if ( MeprRule::is_locked($post) ) unset($results[$k]); } } } return $results; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
August 18, 2020 at 11:36 pm #29040Thank you, Ernest. Unfortunately it is still not working. I believe I’ve found a different way to address the issue: multiple ASP search forms, each with different constraints and conditionally displayed based on login status.
August 19, 2020 at 9:12 am #29053That sounds like a perfect solutions, although I don’t know why the other one does not work, the code seems to be all right.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.