As noted above, when I tried that code I ended up on a server level 404 page. If this is meant to be a standard WordPress search ( ia m not sure if it is) you need to be using name="s"
and not name="q"
. WordPress uses the s
GET
variable for a search.
The following submits to whatever page I specify in my install:
<form method="get" id="searchform" action="<?php echo site_url('sample-page')?>">
<label for="s" class="assistive-text"><?php _e( 'Search', 'lart' ); ?></label>
<input type="text" class="field" name="q" id="s" placeholder="<?php esc_attr_e( 'Search', 'lart' ); ?>" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'lart' ); ?>" />
</form>
So does this:
<form method="get" id="searchform" action="<?php echo get_permalink(2); ?>">
<label for="s" class="assistive-text"><?php _e( 'Search', 'lart' ); ?></label>
<input type="text" class="field" name="q" id="s" placeholder="<?php esc_attr_e( 'Search', 'lart' ); ?>" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'lart' ); ?>" />
</form>
Per comments above, searchpage.php
is the WordPress search page. If you want that page to process your form, you need to use name="s"
and not name="q"
. That is the trigger for WordPress to search. You can then hook to pre_get_posts
to alter how the query is processed.