WordPress.org

Ready to get started?Download WordPress

Forums

Show Future Posts in Date Order (5 posts)

  1. Adam
    Member
    Posted 2 years ago #

    I've got a website that I manage for a local organization. When I built the site a few years ago, I used categories to sort the various sections of the site. The organization has Events which go under the "Events" category. These events would show up in order sorted by date. Since updating WP to 3.3.1 a month or so ago, the Events now show up in the wrong order. I would like for the closest events to be on top, and the further events to be toward the bottom, e.g. March 13, June 15, November 20.

    I thought that changing the order=asc to order=desc would have fixed this, but apparently not. The following code works perfectly, except that the order of the Events won't change! Anyone have any thoughts?

    <?php
    $my_query = new WP_Query('category_name=Events&post_status=future&order=DESC&showposts=5');
    if ($my_query->have_posts()) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <?php the_date(); ?> - <?php the_title(); ?><br />
    
    <?php endwhile;
    }
    ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    even if it is the default, try adding 'orderby=date' to the query, and use 'order=ASC'

    $my_query = new WP_Query('category_name=Events&post_status=future&orderby=date&order=ASC&showposts=5');
  3. Adam
    Member
    Posted 2 years ago #

    Good suggestion, but that still didn't change the events order. Thanks for your help!

    By the way, the site is using WP 3.3.1.

  4. Jusi
    Member
    Posted 1 year ago #

    Hi Adam,

    Have you been able to fix this issue? I'm having the same problem with listing future posts in the correct order - using orderby and order doesn't work for me either. Using WP 3.4.1

  5. Adam
    Member
    Posted 1 year ago #

    Hi Jusi,

    I never got the orderby or order to work. I wound up using custom fields in the way of a super plugin (which I've used for a couple years now) called Advanced Custom Fields.

    http://wordpress.org/extend/plugins/advanced-custom-fields/

Topic Closed

This topic has been closed to new replies.

About this Topic