web analytics

Andreas Viklund WordPress Theme Search Form Not Working

I discovered a problem with the search form file (searchform.php) included with the Andreas Viklund WordPress Theme WP-Andreas01 1.7 version. When searching from the main blog page (the page identified as the location for all posts to be listed), the search form works. However, when using the search form from any other page or destination (such as while viewing categories of writings) the search form doesn’t work. The default search form provided with the default WordPress template does work. So, I created a modified search form based upon the default form and the Andreas Viklund search form. My notes are below. For those of you who are new to WordPress, the searchform.php file contains a few lines of html and php code that will generate a search box. So, on other pages, such as the sidebar, you can request that searchform.php be inserted and it will show up. There may be problems with the search form included with other WordPress themes. If so, the following may be of help.

File: searchform.php

Default Search Form

<form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
<div>
<input type=”text” value=”<?php the_search_query(); ?>” name=”s” id=”s” />
<input type=”submit” id=”searchsubmit” value=”Search” />
</div>
</form>

Andreas Search Form

<h2>Search Articles</h2>
<form method=”get” id=”searchform” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
<div>
<label for=”s”>Search for:</label>
<input type=”text” value=”<?php echo wp_specialchars($s, 1); ?>” name=”s” id=”s” size=”14″ />
<input type=”hidden” id=”searchsubmit” value=”Search” />
</div>
</form>

Modified Search Form

<strong>Search Articles</strong>
<form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
<div>
<input type=”text” value=”<?php the_search_query(); ?>” name=”s” id=”s” />
<input type=”submit” id=”searchsubmit” value=”Search” />
</div>
<p></p>
</form>

Published
Categorized as Technology

By Greg Johnson

Greg Johnson is a freelance writer and tech consultant in Iowa City. He is also the founder and Director of the ResourcesForLife.com website. Learn more at AboutGregJohnson.com