I’ve put together this little loop to display upcoming 4 events from the calendar.
I placed it in sidebar.
On archive page it behaves normally.
But on single post page it goes crazy, and loads 4 events + reloads everything on the page like second sidebar second post and second right sidebar…
Commenting out query stops this insane behavior. So no I didn’t make stupid copy paste mistake 🙂
<ul class="sidebarlists">
<li>
<h2>Upcoming Events</h2>
<span class="seeallside"><a href="http://localhost/wordpress/events/">See All</a></span>
<?php
$postslist = query_posts('order=DESC&orderby=modified&posts_per_page=4&post_type=tribe_events&eventDisplay=upcoming');
echo "<ul>";
foreach ($postslist as $loopID => $p) {
echo "<li>";
echo "<a title='". $p->post_title . "' href='" . get_permalink($p->ID) . "'>".get_the_post_thumbnail( $p->ID, array( 50,50, 'class' => ' sidebarthumb '))."</a>";
echo "<h3><a title='". $p->post_title . "' href='" . get_permalink($p->ID) . "'>".$p->post_title."</a></h3>";
echo "<span>".tribe_get_start_date( $p->ID, true, 'D. M j, Y' )."</span>";
echo " <div class=\"clearfloat\"></div>";
echo "</li>";
}
echo "</ul>";
?>
</li>
<!-- End #sidebarlists --></ul>
Reading here :
http://codex.wordpress.org/Function_Reference/query_posts
it says that you should use “secondary” loops using get_posts(), because query_posts scraps the $post variables
see “Alters Main Loop” AND “Secondary Loops”