Advertisement
Guest User

Untitled

a guest
Oct 19th, 2012
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: events
  4. */
  5. ?>
  6. <?php get_header(); ?>
  7.  
  8. <div id="primary">
  9. <div id="content" role="main">
  10.  
  11. <?php
  12. // $archive = get_post_meta_archive('showdate');
  13. // for custom post types use the second parameter
  14. $archive = get_post_meta_archive('showdate' , 'shows');
  15.  
  16. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  17.  
  18. $temp = $wp_query;
  19. $wp_query= null;
  20. $wp_query = new WP_Query();
  21.  
  22. if(!empty($archive) && isset($archive[$paged-1])) :
  23. $myyear = $archive[$paged-1]->year;
  24. $mymonth = $archive[$paged-1]->month;
  25. // put leading 0 on single digit months
  26. $mymonth =str_pad($mymonth, 2, "0", STR_PAD_LEFT);
  27. $start = $myyear.'-'.$mymonth.'-01';
  28. $end = $myyear.'-'.$mymonth.'-31';
  29. $meta_value = array( $start, $end );
  30.  
  31. $args = array(
  32. 'post_type' => 'shows',
  33. 'posts_per_page' => -1,
  34. 'meta_key' => 'showdate',
  35. 'orderby' => 'meta_value',
  36. 'order' => 'ASC',
  37. 'meta_query' => array(
  38. array(
  39. 'key' => 'showdate',
  40. 'value' => array( $start, $end ),
  41. 'compare' => 'BETWEEN',
  42. 'type' => 'DATE',
  43. )
  44. )
  45. );
  46.  
  47. $wp_query->query($args);
  48. $wp_query->max_num_pages = count($archive);
  49. ?>
  50. <h2>Events for: <?php echo date('F, Y', strtotime($start)); ?></h2>
  51. <!-- the loop -->
  52. <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
  53. <?php echo get_post_meta($post->ID, 'showdate',true) ?>
  54. <?php get_template_part( 'content', 'post' ); ?>
  55.  
  56. <?php endwhile; // end of the loop. ?>
  57. <!-- put your pagination function here -->
  58. <?php posts_nav_link(); ?>
  59.  
  60. <?php else : ?>
  61. <h2>No current events</h2>
  62. <?php endif; ?>
  63. <?php $wp_query = null; $wp_query = $temp; ?>
  64.  
  65. </div><!-- #content -->
  66. </div><!-- #primary -->
  67.  
  68. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement