limit post types on search page

<?php

/* limit types searched on wp search page */
add_action( 'pre_get_posts', function( $query ) {
  if ( !is_admin() && $query->is_main_query() && $query->is_search() ) {
    $query->set('post_type', 'post');
  }
} );