Home › Forums › Calendar Products › Events Calendar PRO › Help needed for displaying past events(archive) of a specific category
- This topic has 3 replies, 2 voices, and was last updated 12 years, 11 months ago by
Jonah.
-
AuthorPosts
-
May 5, 2013 at 2:04 pm #47649
Prateek
ParticipantHi,
I have created a page to display past events(archive) of a specific category. The category part works fine though the events which has already passed is listing along with the upcoming. Please check my code
$arg = array(
‘post_status’=>’publish’,
‘post_type’=>array(TribeEvents::POSTTYPE),
‘posts_per_page’=>40,
//order by startdate from newest to oldest
‘eventDisplay’=>’past’,
‘order’=>’DESC’,
//query events by category
‘tax_query’ => array(
array(‘taxonomy’ => ‘tribe_events_cat’, ‘field’ => ‘slug’, ‘terms’ => ‘150-anniversary’, ‘operator’ => ‘IN’),));
$get_posts = null;
$get_posts = new WP_Query();
$get_posts->query($args);
if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>Any suggestion where i am wrong. you can check the output here http://www.rkmkhar.org/150th-anniversary-events-archive/
Thanks in advance
PratzMay 6, 2013 at 2:12 pm #47720Jonah
ParticipantHi Pratz,
‘eventDisplay’ is not a valid arg you can pass to WP_Query. Only what you see here is: http://codex.wordpress.org/Class_Reference/WP_Query – you can pass in custom field args to target a specific date range with WP_Query. For example: http://chopapp.com/#ktei2z6e
Alternatively you can use tribe_get_events() instead of WP_Query and pass in the eventDisplay arg. We’ve got some examples here: https://theeventscalendar.com/support/documentation/the-events-calendar-template-tags-general-functions/#functiontribe_get_events
I hope that helps but let me know if you have any questions.
– Jonah
May 8, 2013 at 3:53 pm #47959Prateek
ParticipantHi Jonah,
The New code works fine form me except for new issue, the ‘orderby’=>’DESC’, is not working. It will be great if you can tell me where i am wrongHere is my code:
global $post;
$current_date = date(‘j M Y’);
$end_date = date(‘j M Y’, strtotime(‘-730 days’));$get_posts = tribe_get_events(
array(
‘start_date’=>$current_date,
‘end_date’=>$end_date,
‘posts_per_page’=>-1,
‘orderby’=>’DESC’,
‘tax_query’=> array(
array(
‘taxonomy’ => ‘tribe_events_cat’,
‘field’ => ‘slug’,
‘terms’ => ‘150-anniversary’
)
)
) );foreach($get_posts as $post) { setup_postdata($post); ?>
May 9, 2013 at 12:14 pm #48068Jonah
ParticipantHi Prateek,
You cannot use the orderby arg with tribe_get_events() because it uses it’s own sorting functions to sort events by date ASC. If you want to use orderby you’ll need to use WP_Query and then set your date ranges appropriately.
I hope that helps!
-
AuthorPosts
- The topic ‘Help needed for displaying past events(archive) of a specific category’ is closed to new replies.
