A user on the Spanish forum (@jrberguill) found the answer and shared it here in case it might help someone else.
// Restrict searches to posts only
function limit_search_posts($query) {
if ( ! is_admin() && $query->is_search() ) {
$query->set(‘post_type’, ‘post’);
}
return $query;
}
add_filter(‘pre_get_posts’, ‘limit_search_posts’);
This will limit WordPress searches to posts on the front end of the site.
If you want to include additional content in the search, modify the line $query->set('post_type', 'post');
by adding them, separated by commas.
For example, to search in posts and pages: $query->set('post_type', array('post', 'page'));
Best regards.