Need to be able to sort events by the date they are created.

Home Forums Calendar Products Events Calendar PRO Need to be able to sort events by the date they are created.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1147790
    Andrew Shepherd
    Participant

    I’m using Events Calendar PRO to list concerts. One of the filters for looking up shows is “Just Announced” which will return the 8 most recent shows that have been created. Has anyone had any success with this? Thanks!

    #1147906
    Nico
    Member

    Hi Andrew,

    Thanks for reaching out to us! I can help you here…

    One of the filters for looking up shows is “Just Announced” which will return the 8 most recent shows that have been created.

    You can use Pro Widget Shortcodes to embed a list of the latest events.

    If the above is not what you are looking for please describe a bit more how you are getting these ‘filtered’ lists of events. If you are coding this yourself you can look into using tribe_get_events function.

    Please let me know about it,
    Best,
    Nico

    #1148211
    Andrew Shepherd
    Participant

    Nico,

    Originally I created a custom post type called “shows” and did a WP_Query to get the 8 most recent shows posted using the following code. I also used the Advanced Custom Fields plugin to add fields like Door Time, Ticket Price, Restrictions, etc.

    $just_announced_args = array(
    	'post_type' => 'shows', 
    	'posts_per_page' => 8, 
    	'orderby' => 'date', 
    	'order' => 'DESC', 
    	'status' => 'publish');
    
    $justannouncedshows = new WP_Query( $just_announced_args );	
    while ( $justannouncedshows->have_posts() ) : $justannouncedshows->the_post();
    
    endwhile;
    

    This query and loop got me what I needed.
    This is the query I’m using to get the events sorted by the start date which pulls in the info correctly.

    global $post;
     
    // Retrieve all upcoming events
    $events = tribe_get_events( array(
        'posts_per_page' => -1,
        'start_date' => date( 'Y-m-d' )
    ) );

    Here is my query for trying to pull in the 8 most recent shows added to the Events Calendar.

    $events = tribe_get_events( array(
    	    'posts_per_page' => 8,
    	    'post_type' => 'tribe_events',
    	    'orderby' => 'date', 
    		'order' => 'DESC', 
    		'status' => 'publish'
    	) );
    #1149193
    Nico
    Member

    Thanks for following up Andrew!

    I’m a bit confused about this, could you actually make it work?

    I gave this a quick try and this is the one that works for me:

    function tribe_dump_events ( ){
    $events = get_posts( array(
    'posts_per_page' => 8,
    'post_type' => 'tribe_events',
    'orderby' => 'date',
    'order' => 'DESC',
    'post_status' => 'publish'
    ) );

    echo '

    ';
    	var_dump($events);
    	echo '

    ';
    }
    add_action ( 'init', 'tribe_dump_events');

    When using ‘tribe_get_events’ it seems that the order and orderby clauses are overwritten at some point. Also please note that post_status is the correct parameter to query posts by status and not status as you are using!

    Please let me know if this is still an issue or if it’s solved,
    Best,
    Nico

    #1149383
    Andrew Shepherd
    Participant

    YES!!!! That was it! Thank you so much!

    I ended up using the following from what you gave me above.

    $events = get_posts( array(
            'posts_per_page' => 8,
            'post_type' => 'tribe_events',
            'orderby' => 'date', 
            'order' => 'DESC', 
            'post_status' => 'publish'
        ) );
    #1149390
    Nico
    Member

    Perfection! Glad to be service 🙂

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Need to be able to sort events by the date they are created.’ is closed to new replies.