I have the following template page which pulls in a list of shows from an XML feed…

<?php
/*
  Template Name: Shows
*/

$genre = '';
$month = 0;

/*if(isset($wp_query->query_vars['genre'])) {
  $genre = $wp_query->query_vars['genre'];
}*/

if(isset($wp_query->query_vars['genre'])) {
  $genre = urldecode($wp_query->query_vars['genre']);
}

if(isset($wp_query->query_vars['month'])) {
  $month = $wp_query->query_vars['month'];
}

?>

<?php get_header(); ?>

<script type="text/javascript">

  jQuery(document).ready(function() {

    jQuery('#selGenre').change(function() {
      var genre = jQuery(this).val();
      window.location.href = '/theatre/whats-on?genre=' + genre;
    });

    jQuery('#selMonth').change(function() {
       var month = jQuery(this).val();
       window.location.href = '/theatre/whats-on?month=' + month;
    });

    jQuery('.box').mouseenter(function(){
      jQuery('.caption').stop().animate({height: "100%"});
    });

    jQuery('.box').mouseleave(function(){
      jQuery('.caption').stop().animate({height: "20%"},  1000, function() { });
    });

  });

</script>

  <!-- RIP SUB MENU -->

  <div class="sub-nav-container-full rip-sub-menu">
<div class="container">
<div class="col-md-7">
  <div class="sub-page-menu">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("second-level-menu") ) : ?><?php endif;?>
  </div>
</div>
<div class="col-md-5">
  <div class="blue-cta">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("blue-strip-cta") ) : ?><?php endif;?>
  </div>
</div>
</div>
</div>





<!-- SHOW PAGE FEATURED IMAGE -->

      <!-- <div class="featured-image-show">
        <?php the_post_thumbnail(); ?>
      </div>
 -->





  <!-- HEADER AND TOP CONTENT -->

  <div class="container">
    <div class="col-md-12">

      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <div class="page-header">
          <h1><?php the_title(); ?></h1>
        </div>

        <?php the_content(); ?>

      <?php endwhile; else: ?>

        <div class="page-header">
          <h1>Oh no!</h1>
        </div>

        <p>No content is appearing for this page!</p>

      <?php endif; ?>

    </div>
  </div>

  <!-- PULL IN SHOW FEED  -->

  <div class="container">
      <div class="col-md-12 whats-on-feed">

        <div class="row">
          <div class="col-md-6">
            <select id="selGenre" name="selGenre">
              <option value="">Genre...</option>
              <option value="all" <?=$genre == 'all' ? ' selected="selected"' : '';?>>All</option>
              <option value="Comedy" <?=$genre == 'Comedy' ? ' selected="selected"' : '';?>>Comedy</option>
              <option value="Performance" <?=$genre == 'Performance' ? ' selected="selected"' : '';?>>Performance</option>
              <option value="Music" <?=$genre == 'Music' ? ' selected="selected"' : '';?>>Music</option>
              <!-- <option value="Family" <?=$genre == 'Family' ? ' selected="selected"' : '';?>>Children & Families</option> -->
              <option value="<?php echo urlencode("Children & Families"); ?>" <?=$genre == 'Children & Families' ? ' selected="selected"' : '';?>>Children & Families</option>
              <option value="Introducing" <?=$genre == 'Introducing' ? ' selected="selected"' : '';?>>Introducing</option>
              <option value="Dance" <?=$genre == 'Dance' ? ' selected="selected"' : '';?>>Dance</option>
              <option value="Spoken Word" <?=$genre == 'Spoken Word' ? ' selected="selected"' : '';?>>Spoken Word</option>
              <option value="Fundraising" <?=$genre == 'Fundraising' ? ' selected="selected"' : '';?>>Fundraising</option>
              <option value="">Show All</option>
            </select>
          </div>
          <div class="col-md-6">
            <select id="selMonth" name="selMonth">
             <option value="0" <?=$month == '0' ? ' selected="selected"' : '';?>>Month...</option>
             <option value="01" <?=$month == '01' ? ' selected="selected"' : '';?>>January</option>
             <option value="02" <?=$month == '02' ? ' selected="selected"' : '';?>>February</option>
             <option value="03" <?=$month == '03' ? ' selected="selected"' : '';?>>March</option>
             <option value="04" <?=$month == '04' ? ' selected="selected"' : '';?>>April</option>
             <option value="05" <?=$month == '05' ? ' selected="selected"' : '';?>>May</option>
             <option value="06" <?=$month == '06' ? ' selected="selected"' : '';?>>June</option>
             <option value="07" <?=$month == '07' ? ' selected="selected"' : '';?>>July</option>
             <option value="08" <?=$month == '08' ? ' selected="selected"' : '';?>>August</option>
             <option value="09" <?=$month == '09' ? ' selected="selected"' : '';?>>September</option>
             <option value="10" <?=$month == '10' ? ' selected="selected"' : '';?>>October</option>
             <option value="11" <?=$month == '11' ? ' selected="selected"' : '';?>>November</option>
             <option value="12" <?=$month == '12' ? ' selected="selected"' : '';?>>December</option>
            </select>
          </div>
        </div>

        <br />

        <?php
            $xml = simplexml_load_file('https://tickets.leicesterymca.co.uk/feed/shows');

            if(isset($wp_query->query_vars['month'])) {
              $month = $wp_query->query_vars['month'];
              $fromDate = date("Y"). '-'. $month;
              $shows = $xml->xpath("//*[contains(ActiveFrom,'$fromDate')]");
            }else if(isset($wp_query->query_vars['genre'])) {
              $genre = str_replace("-", " ", $wp_query->query_vars['genre']);

              if($genre != 'all'){
                $shows = $xml->xpath("//*[Genres/Genre/@Name='$genre']");
              }else{
                $shows = $xml;
              }

            }else{
              $shows = $xml;
            }
        ?>

        <div class="block-grid-xs-1 block-grid-sm-2 block-grid-md-3 block-grid-lg-4 show-list">
        <?php
            $i = 1;

            foreach ($shows as $Show) {

              $activeFrom=date_create($Show->ActiveFrom);
              $activeTo=date_create($Show->ActiveTo);

              if(strlen($Show->ShowId) > 0){
        ?>
        <div>
         <div class="box">
          <div class="caption">
           <h3><?php echo $Show->Name ?></h3>
           <p><?php echo $activeFrom->format('D d M Y'); ?></p>
           <div class="row">
             <div class="col-xs-6 col-sm-6 col-md-6">
               <a href='/show?showid=<?php echo $Show->ShowId ?>' class='btn btn-success btn-sm btn-clear-white'>More Info</a>
             </div>
             <div class="col-xs-6 col-sm-6 col-md-6">
               <a href='/buy?showid=<?php echo $Show->ShowId ?>' class='btn btn-success btn-sm btn-clear-white'>Buy Tickets</a>
             </div>
           </div>
          </div>
          <div class='image-holder' style='background-image: url("<?php echo $Show->SmallImageUrl ?>");' /></div>
         </div>
        </div>
        <?php $i++; }} ?>
      </div>
  </div>

  <!-- BOTTOM CONTENT AREA -->

  <div class="container">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <div class="bottom_content_area">
      <?php the_field('bottom_content_area'); ?>
    </div>

    <?php endwhile; else: ?>

    <?php endif; ?>
  </div>

<?php get_footer(); ?>

The page can be seen here: https://www.leicesterymca.co.uk/theatre/whats-on/

The problem is, currently it is ordered by show ID. I would like to actually order it by the xml node: ActiveFrom which is the start date of the shows, rather than by the Show ID…

I’m not sure which part of the code to alter or even if it would need new code to do this.

Many thanks…

Read more here: Re-order items pulled in from xml feed


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: