Support » Plugin: The Events Calendar » [Plugin: The Events Calendar] Cannot change order of posts in query_posts

  • Resolved pealo86


    I’m using the following code to insert some events into a page on my website:

    $args = array(
    		'post_type' => 'tribe_events',
    		'posts_per_page' => 3,
    		'orderby' => 'title',
    		'order' => 'DESC'

    But it is ignoring the order that I specify. All it’s doing is showing the 3 oldest events (ordered by the dates in which they were published), all of which have passed their date.

    I cannot set the order in any other way, even alphabetically.

    Does anyone else have this problem? If I switch the query to default posts I do not have this issue.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Mario Peshev


    Have you tried using the tribe_get_events() function which wraps the get_posts one? There is a sample of it here



    Hmmm I’ve tried that, but I’m having the exact same problem! These posts just don’t seem to wanna display in a different order :/



    Never mind actually, I worked around it with this 😉



    I use this :


    Plugin Author Rob La Gatta


    Sounds like everyone here is set, based on what I’m reading in here (thanks to nofearinc for his tip too). Pealo86 found a workaround, and 7h47 has a solution too.

    It seems the issue is resolved so I’m going to mark it as such right now. But if anyone disagrees with this action or needs something else down the road, please let us know and we’ll get it over with haste.

    I still have the same problem as the people above. No matter what I do for order in the array, my list outputs in the order the order they were entered.

    global $post;
    $all_events = tribe_get_events(array(
    	'order'=>'ASC' //no matter what I change it to, no effect
    foreach($all_events as $post) {

    Nothing special going on there. Tried the plugin, which I’m wary of using anyhow, and no effect.

    Can I set up a meta query and orderby the first date box? Can you suggest the syntax?

    Plugin Author Rob La Gatta


    Hey, Watermelonkid – thanks for the note here, and sorry to hear this hasn’t done the trick. Mind sharing a link to the site (so I can get a dev to respond after taking a look at the issue directly)? Thanks in advance!

    Hello again,
    Turns out my workaround wasn’t really much of a workaround as it was just reversing the order of the posts, I still couldn’t re-order them by any other field.

    I therefore had one of my programmer friends look into it for me and he came up with a solution, kind of over my head… but it’s fixed it nonetheless!

    Just for the record, here is what he did:

    	$args = array(
    			'post_type' => 'tribe_events',
    			'posts_per_page' => 3
    	 add our own filter to override what the event plugin.
    	 Using a priority of 99 makes it load after the even plugin has messed with things
    	add_filter( 'pre_get_posts', 'use_our_own_damn_order_value', 99 );
    	function use_our_own_damn_order_value( $query ) {
    			$query->set( 'orderby', 'meta_value' );
    			$query->set( 'meta_key', '_EventStartDate' );
    			$query->set( 'order', 'ASC' );
    		return $query;
    	$our_events = new WP_Query( $args );
    	<?php while ( $our_events->have_posts() ) : $our_events->the_post(); ?>

    Plugin Author Rob La Gatta


    This is great…thanks for sharing it, pealo86. It should be of value to folks who experience the same issue down the road and we appreciate it.

    As always, let us know if you need anything else. Thanks again for using The Events Calendar.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: The Events Calendar] Cannot change order of posts in query_posts’ is closed to new replies.