I think I made this more complicated for myself than it had to be. have a lot of template files in my theme directory, but I don’t have a home.php. I’m going to make my homepage follow the home.php template and see if that clears up my search/subpage template problem.
So that didn’t work. I moved my index.php to home.php and the WP Custom Fields Search results still show up as though it thinks it is the homepage.
Any thoughts on code I can add to this plugin to make it not use the homepage template? Any of this make sense?
Short answer: yes!
Nothing worked the way I was trying to code, so I had to go around the issue. Basically what I did was to code my search.php to point to another search template if the search came in from the website’s main search, otherwise use the custom search template for everything else.
Here’s how to do this…
Modify your search.php file in your theme:
<?php
/* Template Name: Search Results */
$search_refer = $_GET["site_section"];
if ($search_refer == 'blog') { load_template(TEMPLATEPATH . '/search-sitesearch.php'); }
else { load_template(TEMPLATEPATH . '/search-customfieldsearch.php'); };
?>
Then modify your main website search to include the search_refer parameter from the above code. Here’s my site search form code:
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<input type="text" name="s" id="s" value="Search everything..." onblur="if(this.value=='') this.value='Search';" onfocus="if(this.value=='Search everything...') this.value='';" />
<input type="hidden" name="site_section" value="blog" class="hidden" />
<button type="submit" id="searchsubmit" value="Search" class="submit">Submit</button>
</form>
In the hidden input class above we are telling any searches coming from this form need to have the value of ‘blog’ along with it. In the first piece of code above we tell WP which template to use if the search_refer equals ‘blog’.
Let me know if I need to explain this more. The Custom Field Search is awesome, but it’s quirky and doesn’t seem to be too flexible or supported.
Of course, there’s always this: How to Customize Multiple Search Result Pages in WordPress: http://tinyurl.com/l5m3ln
Really interesting, thanks alot!!!