WordPress.org

Ready to get started?Download WordPress

Forums

The Events Calendar
[resolved] Cannot change order of posts in query_posts (10 posts)

  1. pealo86
    Member
    Posted 2 years ago #

    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'
    );
    query_posts($args);

    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.

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. nofearinc
    Member
    Posted 2 years ago #

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

  3. pealo86
    Member
    Posted 2 years ago #

    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 :/

  4. pealo86
    Member
    Posted 2 years ago #

    Never mind actually, I worked around it with this ;)

    http://wordpress.org/extend/plugins/sort-query-posts/

  5. 7h47
    Member
    Posted 2 years ago #

    I use this :

    eventDisplay=upcoming
    orderby=EventStartDate
    order=asc

  6. roblagatta
    Modern Tribe Support
    Plugin Author

    Posted 2 years ago #

    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.

  7. watermelonkid
    Member
    Posted 2 years ago #

    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(
    	'eventDisplay'=>'upcoming',
    	'posts_per_page'=>3,
    	'order'=>'ASC' //no matter what I change it to, no effect
    ));
    
    foreach($all_events as $post) {
    	setup_postdata($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?

  8. roblagatta
    Modern Tribe Support
    Plugin Author

    Posted 1 year ago #

    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!

  9. pealo86
    Member
    Posted 1 year ago #

    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:

    <?php
    	$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(); ?>
  10. roblagatta
    Modern Tribe Support
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic