WordPress.org

Ready to get started?Download WordPress

Forums

Sort by date, then alpha (5 posts)

  1. rhammill
    Member
    Posted 8 years ago #

    This may be a little unusual, but I am trying to sort my posts by date, but then alphabetically within that date.

    It seems that no matter what I have tried, it sorts either alphabetically, or by date and time.

    Any ideas?

    Thanks,

    Randy

  2. As in per day? per month?

    Either way, the problem is that the date/time of a post is all in one column (which is almost always how it is), but that makes it difficult (unless I'm missing something) to do what you're asking.

    Currently, the only way I can think to do this is to make a query for each day. Although I just though of another way to do it. I'll get back to you.

  3. rhammill
    Member
    Posted 8 years ago #

    By day. For example, what if you wanted to make a list of people's birthdays. The date is important, but not the specific time, and it would be easier to go through a list alphabetically.

    I started with the alphabatizing posts script and modified that to look like this:
    <?php
    // we add this, to show all posts in our
    // Glossary sorted alphabetically
    if (is_category('Glossary'))
    {
    $posts = query_posts($query_string .
    '&orderby=date&orderby=title&order=asc&posts_per_page=-1');
    }
    // here comes The Loop!
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    ***********

    This just ends up alphabatizing it. If I comment out the &orderby=title then it sorts by date and accepts the ascending command.

    I also tried &orderby=year&orderby=month&orderby=day, but I'm not even sure if those are recognized terms. It didn't give me an error though.

    Thanks,

    Randy

  4. That won't work as if you order by date, that's ordering by date AND time.

  5. rhammill
    Member
    Posted 8 years ago #

    As I discovered ... although the MySQL reference says the date function extracts only the date and not the time.

Topic Closed

This topic has been closed to new replies.

About this Topic