wordpress search bar for page that search only particular page id’s

How can i create a search bar in a page that searches only in particular page id’s. This shouldn’t affect the search bar in other pages.

I tried

Read More
add_filter( 'pre_get_posts', 'pregetposts_forspecificpage' );

function pregetposts_forspecificpage($query){
   if ($query->is_search) {
   $query->set('post_type', 'page');
   $query->set('post__in', array(22103,22121));
   }
   return $query;
}

But it affects search bars in other pages. How can i accomplish this ?

Related posts