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

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30256
    fvolonterio43fvolonterio43
    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
    Ernest MarcinkoErnest Marcinko
    Keymaster
    #30267
    fvolonterio43fvolonterio43
    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
    Ernest MarcinkoErnest Marcinko
    Keymaster

    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;
    }
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.