Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Excluding specific Pages, Articles and Posts from search › Reply To: Excluding specific Pages, Articles and Posts from search
November 13, 2020 at 9:57 am
#30269
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;
}