I've spent a lot of time figuring out why my search is not working in my custom made template. So far I was able to figure out how to include searchform.php file in my header, created search.php file which is currently empty (so at the moment when I search for something I get redirected to a blank page and I think I definitely need something in search.php file to make it work), I was reading all around Wordpress codex but could not find a solution, only useful information I found was this.
http://codex.wordpress.org/Creating_a_Search_Page
Can you suggest what need's to be done in order to display results of a search? is there a special query, function etc? I really can't find it anywhere.
my searchform.php file in case you need it.
<form action="<?php echo home_url(); ?>" id="search-form" method="get">
<input type="text" name="s" id="s" value="type your search" onblur="if(this.value=='')this.value='type your search'"
onfocus="if(this.value=='type your search')this.value=''" />
<input type="hidden" value="submit" />
</form>
you need to include the Wordpress loop in your search.php this is example
search.php template file:
Check whether your template in
theme
folder containssearch.php
andsearchform.php
or not.WordPress include tags, categories and taxonomies in search results
This code is taken from http://atiblog.com/custom-search-results/
Some functions here are taken from twentynineteen theme.Because it is made on this theme.
This code example will help you to include tags, categories or any custom taxonomy in your search. And show the posts contaning these tags or categories.
You need to modify your search.php of your theme to do so.
I am using
searchform.php
andsearch.php
files as already mentioned, but here I provide the actual code.Creating a Search Page
codex
page helps here and#Creating_a_Search_Page_Template
shows the search query.In my case I pass the
$search_query
arguments to the WP_QueryClass
(which can determine if is search query!). I then run The Loop to display the post information I want to, which in my case is the the_permalink andthe_title
.Search box form:
search.php
template file:Basically, you need to include the Wordpress loop in your search.php template to loop through the search results and show them as part of the template.
Below is a very basic example from The WordPress Theme Search Template and Page Template over at ThemeShaper.