Advertisement
davidfcarr

RSVPMaker Excerpt Shortcode

Aug 31st, 2012
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. function rsvpmaker_excerpt ($atts)
  2. {
  3.  
  4. $no_events = (isset($atts["no_events"]) && $atts["no_events"]) ? $atts["no_events"] : 'No events currently listed.';
  5.  
  6. global $post;
  7. global $wp_query;
  8. global $wpdb;
  9.  
  10. $backup = $wp_query;
  11.  
  12. add_filter('posts_join', 'rsvpmaker_join' );
  13. add_filter('posts_where', 'rsvpmaker_where' );
  14. add_filter('posts_groupby', 'rsvpmaker_groupby' );
  15. add_filter('posts_orderby', 'rsvpmaker_orderby' );
  16. add_filter('posts_distinct', 'rsvpmaker_distinct' );
  17. remove_filter('the_content','event_content',5);
  18.  
  19. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  20.  
  21. $querystring = "post_type=rsvpmaker&post_status=publish&paged=$paged";
  22. if(isset($atts["type"]))
  23.     $querystring .= "&rsvpmaker-type=".$atts["type"];
  24. if(isset($atts["limit"]))
  25.     $querystring .= "&posts_per_page=".$atts["limit"];
  26. if(isset($atts["add_to_query"]))
  27.     {
  28.         if(!strpos($atts["add_to_query"],'&'))
  29.             $atts["add_to_query"] = '&'.$atts["add_to_query"];
  30.         $querystring .= $atts["add_to_query"];
  31.     }
  32.  
  33. $wp_query = new WP_Query($querystring);
  34.  
  35. // clean up so this doesn't interfere with other operations
  36. remove_filter('posts_join', 'rsvpmaker_join' );
  37. remove_filter('posts_where', 'rsvpmaker_where' );
  38. remove_filter('posts_groupby', 'rsvpmaker_groupby' );
  39. remove_filter('posts_orderby', 'rsvpmaker_orderby' );
  40. remove_filter('posts_distinct', 'rsvpmaker_distinct' );
  41.  
  42. ob_start();
  43.    
  44. if ( have_posts() ) {
  45. while ( have_posts() ) : the_post();
  46.  
  47. $sql = "SELECT * FROM ".$wpdb->prefix."rsvp_dates WHERE postID=".$post->ID.' ORDER BY datetime';
  48. $results = $wpdb->get_results($sql,ARRAY_A);
  49. if($results)
  50. {
  51. $dateblock = '';
  52. foreach($results as $row)
  53.     {
  54.     $t = strtotime($row["datetime"]);
  55.     if(!empty($dateblock))
  56.         $dateblock .= ', ';
  57.     $dateblock .= date('F jS',$t);
  58.     }
  59. }
  60. ?>
  61.  
  62. <div id="post-<?php the_ID();?>" <?php post_class();?> >
  63. <h3 class="entry-title"><a href="<?php the_permalink(); ?>" ><?php the_title(); echo ' - '.$dateblock; ?></span></a></h3>
  64. <div class="entry-content">
  65. <?php the_excerpt(); ?>
  66. </div><!-- .entry-content -->
  67. </div>
  68. <?php
  69. endwhile;
  70. }
  71. else
  72.     echo "<p>$no_events</p>\n";
  73. $wp_query = $backup;
  74.  
  75. add_filter('the_content','event_content',5);
  76.  
  77. wp_reset_postdata();
  78.  
  79. return ob_get_clean();
  80.  
  81. }
  82.  
  83. add_shortcode("rsvpmaker_excerpt","rsvpmaker_excerpt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement