Support » Plugin: The Events Calendar » The Events Calendar Template display bug

  • Resolved reageek

    (@reageek)


    Having something very odd here, was wondering if someone could inform me why the function below grabs all previous months events up to the end date? ( say you grab events the month of march it will grab all the events for jan and feb. I have added this to my function.php and have been simply calling it from there with
    <?php get_month_events(date('Y M'));?>

    The bases for this function belongs to the second example From Modern Tribes Documentation

    function get_month_events($month){
    	if(isset($GLOBALS['post'])){unset($GLOBAL['post']);}
    	global $post; // DECLARE GLOBAL
    	$currnt_date = '1 '. $month;
    	$end_date = date('j M Y', strtotime("+1month", strtotime($current_date)));
    	// debug line echo "<p>the month passed was " . $month . "</p><p> start date was " . $current_date . "</p><p>and end date was ". $end_date . "</p>";
    
    	$get_posts = tribe_get_events(array('start_date'=>$start_date,'end_date'=>$end_date,'posts_per_page'=>3) );
    
    	foreach($get_posts as $post) { setup_postdata($post);
    		/**
    		 * HTML TEMPLATE BEGINS!
    		 */
    		?>
    
    		<li class="cal-post">
    			<span class="event-date"><a href="<?php the_permalink(); ?>"><?php echo tribe_get_start_date($post->ID, true, 'M j, Y'); ?></a></span>
    	        <h5 class="event-title"><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h5>
    	        <p class="event-content"><?php the_content(); ?></p>
    	    </li>
    
    	<?php
    		/**
    		 * HTML TEMPLATE ENDS
    		 */
    
    	} //endforeach
    	 wp_reset_query();
     }//endfunction

    Thanks in advance for any replies and advice!

    https://wordpress.org/plugins/the-events-calendar/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Barry

    (@barryhughes-1)

    I’m afraid we can’t help with custom development questions here on the free support forum. Please also note that that documentation relates to a previous and no longer supported version of the plugin:

    Please note that all documentation below is for The Events Calendar 2.0.1 through 2.0.11. Documentation for version 3.0 and beyond is available on our main documentation page.

    Thread Starter reageek

    (@reageek)

    Barry,
    Thank you for your post. I found a work around if anyone else would care to view it here it is:

    function get_month_events($month){
    	$current_date = '1 '. $month;
    	$end_date = date('Y-m-d', strtotime("+1month", strtotime($current_date)));
    	$start_date = date('Y-m-d', strtotime($current_date));
    
    	/* The query
    	 * default function for The Events Calendar
    	 * documented feature does not work -> tribe_get_events(array('start_date'=>$current_date,'end_date'=>$final_date,'posts_per_page'=>30); ...depricated!
    	 * can be found at https://tri.be/support/documentation/the-events-calendar-template-tags-general-functions/#functiontribe_get_events
    	 * documentation for 3.0+ can be found at http://docs.tri.be/Events-Calendar/ does not suggest/allow event details of just one month...
    	 *... you can return one day or any upcoming events to a limit.
    	 *
    	 * Custom query
    	 * for return values just print_r($get_post); after $get_posts before foreach loop
    	 *
    	*/
    
    	$query = "SELECT * 	FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.id = wp_postmeta.post_id	WHERE meta_key =  '_EventStartDate'	AND meta_value >=  \"$start_date\"	AND meta_value <  \"$end_date\"	AND post_status = \"publish\" LIMIT 3;";
    	global $wpdb;
    	$get_posts = $wpdb->get_results($query);
    
    	foreach($get_posts as $post) { 
    
    		/**
    		 * HTML TEMPLATE BEGINS!
    		 */
    		?>
    
    		<li class="cal-post">
    			<span class="event-date"><?php echo tribe_get_start_date($post->ID, true, 'M j, Y'); ?>,</span><br/>
    	        <span class="event-title"><?=$post->post_title ?></span><br/>
    	        <span class="event-content"><a href="<?='event/' . $post->post_name; ?> ?>" id="post-<?=$post->post_id; ?>">Click for more details ></a></span>
    	    </li>
    
    	<?php
    		/**
    		 * HTML TEMPLATE ENDS
    		 */
    
    	} //endforeach
    
     }//endfunction

    Enjoy

    Barry

    (@barryhughes-1)

    Excellent, thanks for sharing 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘The Events Calendar Template display bug’ is closed to new replies.