Skip to content

Instantly share code, notes, and snippets.

@bentedder
Created May 30, 2013 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentedder/5681329 to your computer and use it in GitHub Desktop.
Save bentedder/5681329 to your computer and use it in GitHub Desktop.
/*
* This is used to override the WordPress search to ONLY search for a
* custom post type. I used it on a photographer's website (only wanted
* users to search for photo post types).
*
* I put this snippet somewhere in functions.php
*/
function bt_customize_search($form, $search_text, $button_text) {
$onfocus = " onfocus=\"if (this.value == '$search_text') {this.value = '';}\"";
$onblur = " onblur=\"if (this.value == '') {this.value = '$search_text';}\"";
$custom_form = '
<form method="get" action="' . get_option('home') . '/" >
<input type="text" value="'. $search_text .'" name="s"'. $onfocus . $onblur .' />
<input type="hidden" name="post_type" value="CUSTOM_POST_TYPE" />
<input type="submit" value="'. $button_text .'" />
</form>
';
return $custom_form;
}
add_filter('genesis_search_form', 'bt_customize_search', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment