Support

Home Forums Event Espresso Premium Show expored only

Show expored only

Posted: February 23, 2018 at 5:39 am


Rob

February 23, 2018 at 5:39 am

Hi, I have another issue with this event listings on a website that I have been asked to fix!
On this page: http://www.triangleilg.org/past-events/ we want to only show expired events, but no expired are showing, only an event that is still coming up.

I have no idea how to fix this, any help would be appreciated.

Here is the code:

<?php
        $past_events = std_past_events_query();
        if ( count($past_events->posts) > 0 ) {
          if (isset($_GET['y'])) {
            $archive = $_GET['y'];
            if (isset($_GET['m'])) {
              $archive = $_GET['m'] . ' ' . $archive;
            }
          } else {
            $date = get_event_start_date($past_events->posts[0]->EVT_ID);
            $archive = date_format($date, 'F Y');
            //echo $date['date'];
            //var_dump($date);
            //$archive = date('F Y', get_event_start_date($past_events->posts[0]->EVT_ID)->date);
          }

          echo "<h3 style=\"margin-top: 1em;\">" . $archive . "</h3>";

          echo "<div id=\"pe-archive-container\">";

          if (isset($_GET['y'])) {
            $archive_request = 'year="'.$_GET['y'].'"';
            if (isset($_GET['m'])) {
              $archive_request = 'month="'.$_GET['m'].' '.$_GET['y'].'"';
              echo do_shortcode( '[ESPRESSO_EVENTS sort=DESC show_expired="true" '.$archive_request.']' );
              //echo do_shortcode( '[ESPRESSO_EVENTS sort=DESC show_expired="true"]' );
            } else {
              $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
              foreach ($months as $mon) {
                $archive_request = 'month="'.$mon.' '.$_GET['y'].'"';
                //echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true" month="January 2014"]' );
                echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true" month="'.$mon.' 2017"]' );
                //echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true"]' );
                wp_reset_query();
              }
            }
          } else {
            $archive_request = 'month="'.$archive.'"';
            echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true" '.$archive_request.']' );
          }
          echo "</div>";
          ?>
          <?php
          wp_reset_postdata();
        } ?>

And this the shortcode used on the page:

          <?php echo widget_past_events_archive( $past_events->posts ); ?>

I have tried to find the issue but have no idea.
Thank you!


Rob

February 23, 2018 at 5:40 am

Meant to say Show Expired only.


Josh

  • Support Staff

February 23, 2018 at 9:19 am

I’m afraid your there isn’t enough context in your code example to find out why it’s not working, but I can point you in the direction of some simpler code examples that show how to show expired events only:

https://gist.github.com/joshfeck/56bc9e4a3683779fe90f
https://gist.github.com/joshfeck/61a9e21bbc9d4111fbdf


Rob

February 23, 2018 at 9:23 am

Thank you! I am struggling to find where all the event code is located, some is in page file and some is in functions file!


Josh

  • Support Staff

February 23, 2018 at 9:27 am

Loading the entire theme into an IDE may help with that. This way you can search for functions within the entire theme folder.


Rob

February 26, 2018 at 6:36 am

Hi, I think I have found the functions for this, can you take a look and see if you can see any issues:

function custom_archive_list( $all_posts, $is_past_events = false ) {
  if (!$is_past_events) {
    $year = date('Y', strtotime($all_posts[0]->post_date));
  } else {
    $year = date('Y', get_event_start_date($all_posts[0]->EVT_ID));
  }

  $post_counter = 0;
  $by_month = true;
  $month = false;
  $month_num = false;
  $html = '';

  $html .= '<ul class="custom-archive">';
  $html .= '<li><h5>'.$year.'</h5></li>';

  $is_first_month = true;

  foreach ($all_posts as $cur_post) {

    $past_events_page = get_permalink( get_page_by_title( 'Past Events' ) );

    if (!$is_past_events) {
      $date = strtotime($cur_post->post_date);
    } else {
      $date = get_event_start_date($cur_post->EVT_ID);
    }
    if (!$month) $month = date('F', $date);
    if (!$month_num) $month_num = date('m', $date);
    $new_year = date('Y', $date);

    if ($year != $new_year) {
      // its  new year
      if ( $by_month ) {
        if (!$is_past_events) {
          $html .= '<li><a href="'.get_month_link( $year, $month_num ).'">'.$month.' ('.$post_counter.')</a></li>';
        } else {
          $html .= '<li><a href="'.$past_events_page.'?y='.$year.'&m='.$month.'">'.$month.' ('.$post_counter.')</a></li>';
        }
      }
      $year = $new_year;
      if(!$is_past_events) {
        $html .= '<li><h5><a href="'.get_year_link( $year ).'">'.$year.'</a></h5></li>';
      } else {
        $html .= '<li><h5><a href="'.$past_events_page.'?y='.$year.'">'.$year.'</a></h5></li>';
      }

      $post_counter = 0;
      $by_month = false;
    }

    if ( $by_month ) {

      $new_month = date('F', $date);
      if ($month != $new_month) {
        // it's a new month
        // begin counting posts

        if (!$is_past_events) {
          $html .= '<li><a href="'.get_month_link( $year, $month_num ).'">'.$month.' ('.$post_counter.')</a></li>';
        } else {
          $html .= '<li><a href="'.$past_events_page.($is_first_month ? '' : '?y='.$year.'&m='.$month).'">'.$month.' ('.$post_counter.')</a></li>';
        }

        $month = $new_month;
        $month_num = date('m', $date);
        $post_counter = 0;
      }

      $post_counter = $post_counter + 1;

    }
  }

  if ($by_month) {
    if (!$is_past_events) {
      $html .= '<li><a href="'.get_month_link( $year, $month_num ).'">'.$month.' ('.$post_counter.')</a></li>';
    } else {
      $html .= '<li><a href="'.$past_events_page.'?y='.$year.'&m='.$month.'">'.$month.' ('.$post_counter.')</a></li>';
    }
  }

  $html .= '</ul>';
  return $html;
}

function widget_archive() {
  $all_posts = get_posts(array('type' => 'post', 'cat' => '2,3', 'orderby' => 'post_date', 'posts_per_page' => '-1'));
  return '<div class="widget archives"><h4>News Archives</h4><div class="widget-content">'.custom_archive_list( $all_posts, false ).'</div></div>';
}

add_shortcode( 'archive', 'widget_archive' );

function pe_custom_archive_list( $all_posts ) {
  //echo "\n<!-- pe_custom_archive_list() -->";

  if (isset($_GET['y']) && isset($_GET['y'])) {
    $current_query = $_GET['m'].' '.$_GET['y'];
  } else  {
    $date = get_event_start_date($all_posts[0]->EVT_ID);
    $current_query = date_format($date, 'F Y');
    //$current_query = date('F Y', get_event_start_date($all_posts[0]->EVT_ID));
  }

  echo "\n<!-- current query: ".$current_query." -->\n";

  $year = date_format(get_event_start_date($all_posts[0]->EVT_ID), 'Y');
  $post_counter = 0;
  $by_month = true;
  $month = false;
  $month_num = false;
  $html = '';

  $html .= '<ul class="pe-custom-archive">';
  $html .= '<li><h5>'.$year.'</h5><ul>';

  $past_events_url = get_permalink( get_page_by_title( 'Past Events' ) );
  echo "<!-- past events url is ".$past_events_url." -->";

  foreach ($all_posts as $cur_post) {

    $date = get_event_start_date($cur_post->EVT_ID);
    $new_year = date_format($date, 'Y');
    $new_month = date_format($date, 'F');
    echo "\n<!-- ".date_format($date, 'F Y')." -->";

    // if month and month_num haven't been filled, create theme
    if (!$month) $month = date_format($date, 'F');
    if (!$month_num) $month_num = date_format($date, 'm');

    // check if it's a new year and finish the last
    if ($year != $new_year) {

      //$current_query_class = ($new_month.' '.$new_year == $current_query ? ' class="current"' : '');
      $html .= '<li><a href="'.$past_events_url.'?y='.$year.'&m='.$month.'">'.$month.' ('.$post_counter.')</a></li></ul></li>';
      $post_counter = 0;

      // and then move on
      $year = $new_year;
      $month = $new_month;
      $html .= '<li><h5>'.$year.'</h5><ul>';

    } elseif ($month != $new_month) {
      //$current_query_class = ($new_month.' '.$new_year == $current_query ? ' class="current"' : '');
      $html .= '<li><a href="'.$past_events_url.($is_first_month ? '' : '?y='.$year.'&m='.$month).'">'.$month.' ('.$post_counter.')</a></li>';

      // And then move on
      $month = $new_month;
      $post_counter = 0;
    }
    $post_counter = $post_counter + 1;
  }

  //$current_query_class = ($new_month.' '.$new_year == $current_query ? ' class="current"' : '');
  $html .= '<li><a href="'.$past_events_url.'?y='.$year.'&m='.$month.'">'.$month.' ('.$post_counter.')</a></li></ul></li>';
  $html .= '</ul>';
  echo "\n<!-- end -->";
  return $html;

}

function widget_past_events_archive( $post_list = null ) {
  if (!isset($past_events) && $post_list == null) {
    echo "<!-- was not set -->";
    $past_events = std_past_events_query();
    $post_list = $past_events->posts;
  }

  return '<div class="widget archives"><h4>Past Event Archive</h4><div class="widget-content">'.pe_custom_archive_list( $post_list, true ).'</div></div>';
}

add_shortcode('past_events_archive', 'widget_past_events_archive');

Thank you for looking into this! I am at a loss and do not want to totally redo.


Josh

  • Support Staff

February 26, 2018 at 10:41 am

That code doesn’t actually include the std_past_events_query() function.


Rob

February 27, 2018 at 6:15 am

It was in the first post I did, here it is:

<?php
        $past_events = std_past_events_query();
        if ( count($past_events->posts) > 0 ) {
          if (isset($_GET['y'])) {
            $archive = $_GET['y'];
            if (isset($_GET['m'])) {
              $archive = $_GET['m'] . ' ' . $archive;
            }
          } else {
            $date = get_event_start_date($past_events->posts[0]->EVT_ID);
            $archive = date_format($date, 'F Y');
            //echo $date['date'];
            //var_dump($date);
            //$archive = date('F Y', get_event_start_date($past_events->posts[0]->EVT_ID)->date);
          }

          echo "<h3 style=\"margin-top: 1em;\">" . $archive . "</h3>";

          echo "<div id=\"pe-archive-container\">";

          if (isset($_GET['y'])) {
            $archive_request = 'year="'.$_GET['y'].'"';
            if (isset($_GET['m'])) {
              $archive_request = 'month="'.$_GET['m'].' '.$_GET['y'].'"';
              echo do_shortcode( '[ESPRESSO_EVENTS sort=DESC show_expired="true" '.$archive_request.']' );
              //echo do_shortcode( '[ESPRESSO_EVENTS sort=DESC show_expired="true"]' );
            } else {
              $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
              foreach ($months as $mon) {
                $archive_request = 'month="'.$mon.' '.$_GET['y'].'"';
                //echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true" month="January 2014"]' );
                echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true" month="'.$mon.' 2017"]' );
                //echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true"]' );
                wp_reset_query();
              }
            }
          } else {
            $archive_request = 'month="'.$archive.'"';
            echo do_shortcode( '[ESPRESSO_EVENTS show_expired="true" '.$archive_request.']' );
          }
          echo "</div>";
          ?>
          <?php
          wp_reset_postdata();
        } ?>


Josh

  • Support Staff

February 27, 2018 at 6:23 am

No that’s actually not where the std_past_events_query() function is defined.

You can follow this tutorial to help understand the difference between defining a function and calling a function:
https://www.tutorialrepublic.com/php-tutorial/php-functions.php

The support post ‘Show expored only’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Josh 6 months, 4 weeks ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!