Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <form role="search" method="get" id="searchform"
  2. class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
  3. <div>
  4. <label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
  5. <input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
  6. <input type="submit" id="searchsubmit"
  7. value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
  8. </div>
  9. </form>
  10.  
  11. function filter_search_post_type($query) {
  12.  
  13. if ( $query->is_search && ! is_admin() && ! empty($_GET['search_post_type']) ) {
  14. $query->set( 'post_type', array($_GET['search_post_type']) );
  15. }
  16. }
  17.  
  18. return $query;
  19. }
  20.  
  21. add_filter('pre_get_posts','filter_search_post_type');
  22.  
  23. <?php get_search_form(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement