Site icon Hip-Hop Website Design and Development

Is it possible to get the specific content on the search page?

I am working on the WordPress search. I am using the below code to get the data on the search page.

$s=get_search_query();
$args = array(
                's' =>$s
            );
        
 $query = new WP_Query( $args );
 if( $query->have_posts() ) { ?>
    <ul>
 <? while( $query->have_posts() ) { 
        $query->the_post(); 
       // print_r($query);
        
?>
<li><h2><a href='<?php echo the_permalink();?>'><?php echo the_title();?></a></h2></li>
<?php } ?>
    </ul>
    <?php

        };

?>

The above code is working. I am getting the title on the page.

Now, My concern is, Is it possible to get the specific content on the page?

I mean If I use post_content then I am getting all the content of the page. Is it possible to display only section heading on the search page?

using class? or using id?