Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active November 6, 2015 09:54
Show Gist options
  • Select an option

  • Save yratof/0d87beb0ba7494b46fe2 to your computer and use it in GitHub Desktop.

Select an option

Save yratof/0d87beb0ba7494b46fe2 to your computer and use it in GitHub Desktop.
custom post type wordpress search
<form role="search" method="post" class="search-form padding-1" action="<?php echo home_url( '/' ); ?>">
<label>
<span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search FAQs', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
<input class="post_type" type="hidden" name="post_type" value="frequent" />
</label>
<input type="submit" class="search-submit button brand" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" />
</form>
// Custom Search Results for FAQs
function template_chooser($template) {
global $wp_query;
$post_type = get_query_var('post_type');
if( $wp_query->is_search && $post_type == 'frequent' ) {
return locate_template('faq-search.php'); // redirect to archive-search.php
}
return $template;
}
add_filter('template_include', 'template_chooser');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment