Advertisement
firoze

How to Create Advanced Search Form in WordPress for Custom P

Jun 26th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. // How to Create Advanced Search Form in WordPress for Custom Post Types
  2.  
  3. <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
  4. <input type="text" name="s" id="s" <?php if(is_search()) { ?>value="<?php the_search_query(); ?>" <?php } else { ?>value="Enter keywords &hellip;" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"<?php } ?> /><br />
  5.  
  6. <?php $query_types = get_query_var('post_type'); ?>
  7.  
  8. <input type="checkbox" name="post_type[]" value="movies" <?php if (array('movies', $query_types)) { echo 'checked="checked"'; } ?> /><label>movies</label>
  9. <!-- here value="movies" and array(movies) is my post type change your own-->
  10.  
  11. <input type="checkbox" name="post_type[]" value="movies" <?php if (array('movies', $query_types)) { echo 'checked="checked"'; } ?> /><label>movies</label>
  12. <!-- here value="movies" and array(movies) is my post type change your own-->
  13.  
  14. <input type="submit" id="searchsubmit" value="Search" />
  15. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement