Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created October 30, 2011 14:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/1325958 to your computer and use it in GitHub Desktop.
Save billerickson/1325958 to your computer and use it in GitHub Desktop.
Limit search to video
<?php
/**
* Limit Search to Video
* @author Bill Erickson
* @link http://www.billerickson.net/wordpress-search-post-type/
*
* @param string search form
* @param string search text
* @param string button text
* @return string modified search form
*/
function be_search_limit($form, $search_text, $button_text) {
if( !( is_post_type_archive( 'video' ) || is_singular( 'video' ) ) )
return $form;
$onfocus = " onfocus=\"if (this.value == '$search_text') {this.value = '';}\"";
$onblur = " onblur=\"if (this.value == '') {this.value = '$search_text';}\"";
$video_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="video" />
<input type="submit" value="'. $button_text .'" />
</form>
';
return $video_form;
}
add_filter('genesis_search_form', 'be_search_limit', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment