Ascending & descending posts on same page with IF statement

You can’t change the DESC to ASC “within the IF statement”. The query has already ran at that point. I don’t really understand what the code is meant to do though. I don’t really see that code ever producing the pattern you describe. Specifically, I don’t understand what the shortcode strings or for or how that is supposed to work. However, I can duplicate the result. Maybe that will help.

//GET THE CURRENT DATE
$current_date = date('F j, Y');
$current_date = strtotime( $current_date );

$args = array(      
    'orderby'          => 'post_date',
    'order'            => 'DESC',
    'post_type'        => 'post',
    'post_status'      => 'publish',
    'suppress_filters' => true
);

$posts = get_posts( $args );

$expired = array();

// BUILD SHORTCODE CODE TO BE INSERTED
foreach($posts as $post){       
  $event_start_date=get_post_meta($post->ID,'event-start-date',true);
  $event_end_date=get_post_meta($post->ID,'event-end-date',true);

  if (empty($event_start_date) || empty($event_end_date)) continue;
  $event_start=date('F j, Y', $event_start_date);
  $event_end=date('F j, Y', $event_end_date);
  $exp_date = strtotime( $event_end );

  echo '$exp_date > $current_date<br>';
  if( $exp_date > $current_date ) {
    // Match:
    // Event A • July 30, 2015 
    echo the_title(),' &bull; ',$event_end;
    echo '<br>';
  } 
  else {
    array_unshift($expired, get_the_title().' &bull; '.$event_end);
  }
}
echo '$expired<br>';
if (!empty($expired)) {
  echo implode('<br>',$expired);
}

Note: Without going through a bunch of posts and setting the meta fields, which would be tedious, I can’t test this but I have a fair certainty that that is on the right track.

Edit: I did clean up the code a little but it essentially does work. array_unshift prepends items to an array so if the original items are sorted DESC then the array created by array_unshift should be the reverse order.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)