Skip to content

Instantly share code, notes, and snippets.

@mafsdisseny
Forked from billerickson/gist:1325958
Last active August 29, 2015 14:19
Show Gist options
  • Save mafsdisseny/25b2ae16989be46baa9b to your computer and use it in GitHub Desktop.
Save mafsdisseny/25b2ae16989be46baa9b to your computer and use it in GitHub Desktop.
<?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