Anil bhadula
Anil bhadula

Reputation: 203

How to search only post and page title in wordpress?

I want to search according page and post title only. is it possible? my search code in header file is below

<form method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <input type="search" class="form-control" placeholder="<?php esc_attr_e( 'Search...', 'consulting' ); ?>" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" /></div>
    <button type="submit" style="height:7.5vh;"><i class="fa fa-search"></i></button>
</form>

Upvotes: 0

Views: 4165

Answers (1)

Gnanasekaran Loganathan
Gnanasekaran Loganathan

Reputation: 1108

in search.php use below query to override default search functionality or you can use custom template

$args = array(
            'post_type' => 'post',
            's' => $keyword,
            'cat' => $catSearchID,
            'tag'   => $tag-slug,
            'posts_per_page' => -1,
            'location' => $post_location_search ,
        );

$wp_query = new WP_Query($args);

Upvotes: 1

Related Questions