Last active
November 6, 2015 09:54
-
-
Save yratof/0d87beb0ba7494b46fe2 to your computer and use it in GitHub Desktop.
custom post type wordpress search
This file contains hidden or 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
| <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