Guest User

Untitled

a guest
Jun 24th, 2012
366
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×