Home › Forums › Calendar Products › Events Calendar PRO › Need to be able to sort events by the date they are created.
- This topic has 6 replies, 3 voices, and was last updated 7 years, 8 months ago by Andrew Shepherd.
-
AuthorPosts
-
August 4, 2016 at 12:48 pm #1147790Andrew ShepherdParticipant
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!
August 4, 2016 at 5:30 pm #1147906NicoMemberHi 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,
NicoAugust 5, 2016 at 9:32 am #1148211Andrew ShepherdParticipantNico,
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' ) );
August 8, 2016 at 2:13 pm #1149193NicoMemberThanks 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,
NicoAugust 9, 2016 at 6:37 am #1149383Andrew ShepherdParticipantYES!!!! 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' ) );
August 9, 2016 at 7:22 am #1149390NicoMemberPerfection! 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 -
AuthorPosts
- The topic ‘Need to be able to sort events by the date they are created.’ is closed to new replies.