Excluding specific Pages, Articles and Posts from search

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

 
Keymaster
1 year, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30256

    Participant

    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,
    Fabrizzio

    #30261

    Hi 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 :)


    #30267

    Participant

    Hi 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?

    #30269

    Well, 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:

    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;
    }
    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.