custom post types – Is it possible to get the specific content on the search page?

Question

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="https://wordpress.stackexchange.com/questions/400620/<?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?

0
Naren Verma 1 year 2021-12-24T09:03:30-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse