Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Excluding specific Pages, Articles and Posts from search
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 3 years ago.
- AuthorPosts
- November 12, 2020 at 12:10 am #30256
Hi there, im making a private intranet for our team and I decided to use ajax search pro for our search plugin. Im trying to find an option to exclude specific articles, pages or posts from the search but at the moment i’ve been unsuccessful in doing so.
Is there any known way to do this with the plugin? Sorry I cant give access to the website because it has confidential information for our team.
Thank you,
Regards,
FabrizzioNovember 12, 2020 at 9:34 am #30261Hi Fabrizzio,
This should help you: https://documentation.ajaxsearchpro.com/advanced-options/excluding-and-including-results/exclude-by-item-or-id
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 12, 2020 at 9:36 pm #30267Hi Ernest,
Thank you so much for your answer, I was able to exclude the pages that I wanted from the search with your help. This got me thinking if its possible to exclude pages/articles/posts to specific user roles, does ajax allow this option?
November 13, 2020 at 9:57 am #30269Well, I think yes, but will require custom coding for sure. The asp_query_args hook allows appending/changing the search arguments. You could start with something like this:
Best,add_filter("asp_query_args", "asp_query_args_change", 10, 2); function asp_query_args_change($args, $search_id) { if ( current_user_can('editor') ) { $exclude = '1,2,3,4'; // Exclude posts IDs 1, 2, 3 ,4 } else if ( current_user_can('manage_options') ) { exclude = '4,5,6'; } //... // No changes below $args['post_not_in'] = array_unique(array_merge( $args['post_not_in'], explode(',', str_replace(' ', '', $exclude)) )); return $args; }
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.