{"id":1945818,"date":"2020-02-13T12:12:06","date_gmt":"2020-02-13T17:12:06","guid":{"rendered":"https:\/\/theeventscalendar.com\/knowledgebase\/?post_type=tribe-knowledgebase&#038;p=1945818"},"modified":"2024-05-13T15:14:12","modified_gmt":"2024-05-13T19:14:12","slug":"showing-past-events-in-reverse-order","status":"publish","type":"post","link":"https:\/\/theeventscalendar.com\/knowledgebase\/showing-past-events-in-reverse-order\/","title":{"rendered":"Showing Past Events in Reverse Order"},"content":{"rendered":"\n<p>The calendar&#8217;s list and photo views show past events in chronological order by default. That means the oldest events are displayed first and get newer as you go. If you like to show the events in reverse order, where the newest events are displayed first, you can use this snippet.<\/p>\n\n\n\n<p>Add this to your theme&#8217;s <code>functions.php<\/code> file or by using the\u00a0<a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" target=\"_blank\" rel=\"noreferrer noopener\">Code Snippets<\/a>\u00a0plugin. You will then see events showing in reverse chronological order, with the most recent past event at the top of the page in the calendar&#8217;s list and photo views.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/**\n * Changes Past Event Reverse Chronological Order\n *\n * @param array $template_vars An array of variables used to display the current view.\n *\n * @return array Same as above. \n *\/\nfunction tribe_past_reverse_chronological_v2( $template_vars ) {\n\n  if ( ! empty( $template_vars&#x5B;&#039;is_past&#039;] ) ) {\n    $template_vars&#x5B;&#039;events&#039;] = array_reverse( $template_vars&#x5B;&#039;events&#039;] );\n  }\n\n  return $template_vars;\n}\n\/\/ Change List View to Past Event Reverse Chronological Order \nadd_filter( &#039;tribe_events_views_v2_view_list_template_vars&#039;, &#039;tribe_past_reverse_chronological_v2&#039;, 100 );\n\/\/ Change Photo View to Past Event Reverse Chronological Order\nadd_filter( &#039;tribe_events_views_v2_view_photo_template_vars&#039;, &#039;tribe_past_reverse_chronological_v2&#039;, 100 );\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-show-past-events-in-reverse-order-with-a-shortcode\">Show past events in reverse order with a shortcode<\/h2>\n\n\n\n<p>If you are using a shortcode to display your events and would like to show the past events in reverse order there as well, you can add the following snippet to your theme&#8217;s <code>functions.php<\/code> file or by using the\u00a0<a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" target=\"_blank\" rel=\"noreferrer noopener\">Code Snippets<\/a>\u00a0plugin.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\nadd_filter(\n\t&#039;tribe_events_views_v2_view_template_vars&#039;,\n\tfunction( $template_vars, $view ) {\n\t  \t$context = $view-&gt;get_context();\n   \n\t\t\/\/ Not doing a shortcode - bail.\n\t\tif ( empty( $context-&gt;get( &#039;shortcode&#039; ) ) ) {\n\t\t\treturn $template_vars;\n\t\t}\n\t   \n\t\t\/\/ Get the date set for the shortcode and today&#039;s date\n\t\t$targetDate = strtotime($template_vars&#x5B;&#039;request_date&#039;]-&gt;format( &#039;Y-m-d&#039; ));\n\t\t$currentDate = strtotime(date(&quot;Y-m-d&quot;));\n\n\t\t\/\/ If the date set in the past set is_past true\n\t\tif ($targetDate &lt; $currentDate) {\n\t\t\t$template_vars&#x5B;&#039;is_past&#039;] = true;\n\t\t}\n\n\t\t\/\/ reverse order if is_past true\n\t\tif ( !empty( $template_vars&#x5B;&#039;is_past&#039;] ) ) {\n\t\t\t$template_vars&#x5B;&#039;events&#039;] = array_reverse( $template_vars&#x5B;&#039;events&#039;] );\n\t\t}\n   \n\t  \treturn $template_vars;\n\t},\n\t8,\n\t2\n);\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>The calendar&#8217;s list and photo views show past events in chronological order by default. That means the oldest events are displayed first and get newer as you go. If you like to show the events in reverse order, where the newest events are displayed first, you can use this snippet. Add this to your theme&#8217;s&#8230;<\/p>\n","protected":false},"author":3,"featured_media":1955565,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[79],"tags":[25,58],"stellar-product-taxonomy":[161],"class_list":["post-1945818","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippets","tag-customizations","tag-php","stellar-product-taxonomy-the-events-calendar"],"acf":[],"taxonomy_info":{"category":[{"value":79,"label":"Snippets"}],"post_tag":[{"value":25,"label":"Customizations"},{"value":58,"label":"PHP"}],"stellar-product-taxonomy":[{"value":161,"label":"The Events Calendar"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"Jaime Marchwinski","author_link":"https:\/\/theeventscalendar.com\/knowledgebase\/author\/jaimetri-be\/"},"comment_info":0,"category_info":[{"term_id":79,"name":"Snippets","slug":"snippets","term_group":0,"term_taxonomy_id":79,"taxonomy":"category","description":"","parent":0,"count":89,"filter":"raw","term_order":"0","cat_ID":79,"category_count":89,"category_description":"","cat_name":"Snippets","category_nicename":"snippets","category_parent":0}],"tag_info":[{"term_id":25,"name":"Customizations","slug":"customizations","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":109,"filter":"raw","term_order":"0"},{"term_id":58,"name":"PHP","slug":"php","term_group":0,"term_taxonomy_id":58,"taxonomy":"post_tag","description":"","parent":20,"count":85,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1945818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1945818"}],"version-history":[{"count":3,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1945818\/revisions"}],"predecessor-version":[{"id":1960170,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1945818\/revisions\/1960170"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1945818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1945818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1945818"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1945818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}