How to change default post type in wordpress search

How to change default post type in wordpress search

You can change the default search post type for your wordpress website. You can make changes to sidebar or header search form but you must add this line to your Search form.

<input type=”hidden” name=”post_type” value=”post” />

You can change value=”post” to any other post type such as “page”, “product”, “blog”, “news” etc.

The complete code I used in the video is:

<form role=”search” method=”get” class=”search-form” action=”<?php echo site_url(); ?>”>
<label>
<span class=”screen-reader-text”>Search for:</span>
<input type=”search” class=”search-field” placeholder=”Search …” value=”” name=”s”>
<input type=”hidden” name=”post_type” value=”post” />
</label>
<input type=”submit” class=”search-submit” value=”Search”>
</form>

 

 

Please watch the video to better understand.

Leave a Comment