Created
October 10, 2014 22:02
-
-
Save jfeliweb/30dbd022851a834570ea to your computer and use it in GitHub Desktop.
Create multiple Search functions for posts & custom post types and everything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Search Everything*/ | |
function SearchFilter($query) { | |
$post_type = $_GET['post_type']; | |
if (!$post_type) { | |
$post_type = 'any'; | |
} | |
if ($query->is_search) { | |
$query->set('post_type', $post_type); | |
}; | |
return $query; | |
} | |
add_filter('pre_get_posts','SearchFilter'); | |
/* Display Search Field */ | |
<form class="headerForm" role="search" action="<?php bloginfo( 'url' ); ?>/" method="get" id="searchform"> | |
<input type="text" name="s" class="s" id="s" value="" placeholder="Search"/> | |
<button><?php _e("Search");?></button> | |
</form> | |
/* news search form add */ | |
<input type="hidden" name="post_type" value="post" /> | |
/* custom post type listing search form add */ | |
<input type="hidden" name="post_type" value="customtypename" /> | |
/* entire site search don't add anything for value="" */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment