Advertisement
Guest User

Untitled

a guest
Jun 24th, 2012
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. //Script to activate ajax
  2. jQuery(document).ready(function($){
  3. var search_val=$("#s").val();
  4. $('#searchsubmit').click(function(){
  5. $.post(
  6. WPaAjax.ajaxurl,
  7. {
  8. action : 'wpa56343_search',
  9. search_val : search_val
  10. },
  11. function( response ) {
  12. $('#results').append( response );
  13. }
  14. );
  15. });
  16.  
  17. });
  18.  
  19. //function to setup wp_query
  20. add_action('wp_ajax_wpa56343_search', 'wpa56343_search');
  21. function wpa56343_search(){
  22. global $wp_query;
  23. $search = $_POST['search_val'];
  24. $args = array(
  25. 's' => $search,
  26. 'posts_per_page' => 5
  27. );
  28. $wp_query = new WP_Query( $args );
  29.  
  30. get_template_part( 'search-results' );
  31.  
  32. exit;
  33. }
  34.  
  35. //html
  36.  
  37. <div id="my_search">
  38. <form role="search" method="get" id="searchform" action="http://myurl.com/" >
  39. <input type="text" value="" name="s" id="s" />
  40. <input type="submit" id="searchsubmit" value="Search" />
  41. </form>
  42. </div>
  43. <div id="results"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement