0

I have a custom themed site which is not using the correct page template to display search results.

I inherited the site with the theme and I'm now trying to make some changes; I did not create the theme and I cannot reach the person who did, so I'm on my own.

The theme contains searchform.php and search.php files but when the search results are displayed it is using the page.php template instead. I know this because I placed HTML comments in all the template files to show the file name and I'm seeing <!-- TEMPLATE: page.php --> when I inspect the HTML in the browser.

The searchform.php contains:

<form method="get" id="searchform" action="<?php echo esc_url( home_url(  ) ); ?>">
<label for="s" class="assistive-text"><?php _e( 'Search' ); ?></label>
<input type="text" class="field" name='s' value="Search" id="s" placeholder="<?php esc_attr_e( 'enter search term' ); ?>" />
<input type="submit" class="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search' ); ?>" />
</form> 

Common problems I've seen from other people's questions are the form method using POST, not GET, the action URL not sending the search terms to the "home" page, and the search text box name being changed from s to something else, but none of these have been changed in my case. As far as I can see all the settings for the form are correct.

When submitted the search form results in the following URL:

http://www.festivalkidz.com/?s=tent

which via the template hierarchy should use search.php and if that is not available, use index.php. But on my site page.php is used, which is not even on the same "path" as the other search result template options as shown in the Wordpress template hierarchy diagram.

Wordpress Template Hierarchy

I have also seen questions about changing the default template using in a theme for certain pages, with the use of rewrite functions and the like. I cannot find anything of that sort in the functions.php file of the theme; in fact there are no filters installed at all.

The normal methods of debugging problems are to switch to one of the default themes and see if things work but I cannot use that in this case; I am getting the correct search results, just not displayed in the correct page template (theme specific problem).

The other usual thing to do is to disable all plug-ins but I don't see how I can do that on a live site without visitors seeing a "messed up" site while I'm testing; and although we're not massively popular I don't want to disrupt any of the 500 or so visitors we get a day: unless there's a way I can do this sort of testing without causing problems?

So I need help in working out why the wrong template is being used, what else could cause the site to select a different template?

3
  • 1
    "Or can anyone suggest ways to further debug the problem without disrupting the live site?" -- Run the site on a development server and test it there. You should not ever develop on a live site. – s_ha_dum Mar 31 '15 at 22:20
  • Yes, you are correct, I should not be testing on the live site. I guess the wording of my question is a bit misleading, I was hoping for suggestions on tracking down the template problem, not general debugging advice. I'll remove that part of the question. Thanks. – Tony Mar 31 '15 at 22:38
  • There are at least half a dozen ways to mess with template loading, not to mention oddball things a theme/plugin might cook up that I am not thinking about. You need to debug this. I don't think it can be guessed at. – s_ha_dum Apr 1 '15 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.