Advertisement
Guest User

Search.php file for event search

a guest
Dec 12th, 2011
677
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None
  1. <?php get_header(); ?>
  2.  
  3. <!-- CONTENT -->
  4. <div class="content">
  5.  
  6. <div class="content_botbg">
  7.  
  8. <div class="content_res contentbody">
  9.  
  10.  
  11. <!-- left block -->
  12. <div class="content_left">
  13.  
  14.  
  15. <?php if ( have_posts() ) : ?>
  16.  
  17. <?php /* Start the Loop */ ?>
  18. <?php
  19. /*
  20. this is the search query
  21. */
  22. //Check if using meta
  23. $usemeta = false;
  24.  
  25. $args = array(
  26. 'post_type'=>'event', //type the custom post name
  27. 'posts_per_page' => 10, //number of post
  28. 'paged' => $paged, //paged?
  29. 'meta_query' => array( //meta search
  30.  
  31. ),
  32. 'tax_query' => array( //taxonomies search
  33.  
  34. ),
  35. 'orderby' => 'meta_value', //order by meta
  36. 'meta_key' => 'ghes_event_start_timestamp',// change to order by start date
  37. 'order' => 'ASC'
  38. );
  39.  
  40. //if get start date is set add it to meta query
  41. if (isset($_GET['ghes_event_start_timestamp']) && !empty($_GET['ghes_event_start_timestamp'])) {
  42. $args['meta_query'][] = array(
  43. 'key' => 'event_start_timestamp', // change to your meta name
  44. 'value' => $_GET['ghes_event_start_timestamp'],
  45. 'compare' => '>='
  46. );
  47. $usemeta = true;
  48. }
  49. //do the same for end dat
  50. if (isset($_GET['ghes_event_end_timestamp']) && !empty($_GET['ghes_event_end_timestamp'])) {
  51. $args['meta_query'][] = array(
  52. 'key' => 'event_end_timestamp',// change to your meta name
  53. 'value' => $_GET['ghes_event_end_timestamp'],
  54. 'compare' => '<='
  55. );
  56. $usemeta = true;
  57. }
  58.  
  59. $search_refer = $_GET["post_type"];
  60. if ($search_refer == 'event') { load_template(TEMPLATEPATH . '/loop-event_listing.php'); }
  61. //new query
  62. $the_query = new WP_Query( $args );
  63. ?>
  64.  
  65. <?php // The loop ?>
  66. <?php while ($events_query->have_posts() ) : $events_query->the_post(); ?>
  67.  
  68. <?php get_template_part( 'content', get_post_format() ); ?>
  69.  
  70. <?php endwhile; ?>
  71.  
  72. <?php else : ?>
  73.  
  74. <article id="post-0" class="post no-results not-found">
  75. <header class="entry-header">
  76. <h1 class="entry-title"><?php _e( 'Nothing Found', 'gheventstore' ); ?></h1>
  77. </header><!-- .entry-header -->
  78.  
  79. <div class="entry-content">
  80. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'gheventstore' ); ?></p>
  81. <?php get_search_form(); ?>
  82. </div><!-- .entry-content -->
  83. </article><!-- #post-0 -->
  84.  
  85. <?php endif; ?>
  86.  
  87. <div class="clr"></div>
  88.  
  89.  
  90. </div><!-- /content_left -->
  91.  
  92.  
  93. <?php get_sidebar(); ?>
  94.  
  95. <div class="clr"></div>
  96.  
  97.  
  98.  
  99. </div><!-- /content_res -->
  100.  
  101. </div><!-- /content_botbg -->
  102.  
  103. </div><!-- /content -->
  104.  
  105. <?php get_footer(); ?>
  106.  
  107.  
Advertisement
RAW Paste Data Copied
Advertisement