Guest User

Untitled

a guest
Apr 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <div class="panel">
  2. <h2>Search Videos</h2>
  3. <div id="my-search">
  4. <form role="search" method="get" id="searchform" action="http://myurl.com/" >
  5. <input type="text" value="" name="s" id="s" />
  6. <input type="submit" id="searchsubmit" value="Search" />
  7. </form>
  8. </div>
  9. </div>
  10.  
  11. add_action('wp_ajax_wpa5000_search', 'wpa5000_search');
  12. add_action('wp_ajax_nopriv_wpa5000_search', 'wpa5000_search');
  13. function wpa5000_search(){
  14. global $wp_query;
  15. $search = $_POST['search_val'];
  16. $args = array(
  17. 's' => $search,
  18. 'posts_per_page' => 10,
  19. 'cat' => 12,
  20. 'post_type' => array( 'post','fod_videos' )
  21. );
  22. $wp_query = new WP_Query( $args );
  23.  
  24. get_template_part( 'video-search-results' );
  25.  
  26. exit;
  27. }
  28.  
  29. add_action( 'wp_enqueue_scripts', 'wpa56343_scripts', 100 );
  30. function wpa56343_scripts() {
  31. wp_enqueue_script(
  32. 'wpa56343_script',
  33. get_template_directory_uri() . '/libs/search.js?ver=1.0',
  34. array( 'jquery' ),
  35. null,
  36. false
  37. );
  38. wp_localize_script(
  39. 'wpa56343_script',
  40. 'WPaAjax',
  41. array(
  42. 'ajaxurl' => admin_url( 'admin-ajax.php' )
  43. )
  44. );
  45. }
  46.  
  47. $(document).ready(function($){
  48. $('#searchsubmit').click(function(e){
  49. var $panel = $(this).closest(".panel");
  50. $panel.empty();
  51. e.preventDefault();
  52. var search_val=$("#s").val();
  53. $.post(
  54. WPaAjax.ajaxurl,
  55. {
  56. action : 'wpa5000_search',
  57. search_val : search_val
  58. },
  59. function( response ) {
  60. $panel.append( response );
  61. }
  62. );
  63. });
  64. });
  65.  
  66. <?php
  67. while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
  68. //STUFF
  69. <?php endwhile; ?>
  70.  
  71. <input type="hidden" name="post_type" value="fod_videos" />
Add Comment
Please, Sign In to add comment