Custom Search without "s" variable
-
I’ve created a custom search for my blog, which searches custom post types by all sorts of post_meta values.
I’ve got the actual search working great, but I was building it on a homepage to test it, so the form submits to the same page and the loop of results is also displayed there. Everything working.But now to implement it, I want the results to appear on a new page (I suppose a custom version of ‘search.php’) but I’m confused and can’t get it to work.
I was using a search form like this (this is without all the extra <input> sections):
<form name="search" id="searchform" action="<?php bloginfo('url'); ?>/" method="get" role="search"> <input type="text" class="field" name="keyword" id="keyword" placeholder="<?php esc_attr_e( 'Enter to search →', 'agility' ); ?>" value="<?php if(isset( $_GET['keyword'] ) ){ echo $keyword; }?>"/> <input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />However, this fails to send everything to search.php. I figured out that for some reason WordPress needs to have the “s” variable or it doesn’t work. If I was to change the second line to:
<input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Enter to search →', 'agility' ); ?>" value="<?php if(isset( $_GET['keyword'] ) ){ echo $keyword; }?>"/>Then it works fine. The problem is, I want people to be able to search without having to put anything in the keyword field. For example, they might choose from a drop-down to search everything located in the UK, but the search form submits with “s=” (no value for ‘s’) and so WordPress doesn’t go to search.php at all, instead just returning a standard blog loop page.
Is there some way to get around this?
All I want is to be able to submit my search to a page that can handle the custom search.
Any ideas?
Thanks, and hope this makes sense.
The topic ‘Custom Search without "s" variable’ is closed to new replies.