Skip to content

Instantly share code, notes, and snippets.

@awakekat
Created April 3, 2017 04:13
Show Gist options
  • Save awakekat/942819e3a21870c563ee4c9c4913a7aa to your computer and use it in GitHub Desktop.
Save awakekat/942819e3a21870c563ee4c9c4913a7aa to your computer and use it in GitHub Desktop.
Wordpress Custom Search Form
custom-search-form.php
============================================
<div class="content-search">
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo get_site_url(); ?>">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
<?php wp_dropdown_categories( array(
'show_option_all' => 'All Posts',
'orderby' => 'name',
'echo' => 1,
'selected' => $cat,
'hierarchical' => true,
'class' => 'cat-dropdown',
'id' => 'custom-cat-drop',
'value_field' => 'term_id'
) ); ?>
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
</div>
============================================
HTML/PHP
============================================
<?php get_template_part('custom-search-form'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment