• Resolved rperrett

    (@rperrett)


    Need some help with this one please…

    I have many posts that are in reverse chronological order that we need to flip to chronological order. The site is an online school with 2-4 posts per day.

    I need to first order by day, then by title. However orderby date also uses time of day and thus orders everything not just the days.

    What we have now:
    May 31st, 11:33 am Sat 31/05/14 – Session 1
    May 31st, 10:40 am Sat 31/05/14 – Session 2
    May 31st, 9:38 am Sat 31/05/14 – Session 3
    May 29th, 7:40 pm Thu 29/05/14 – Session 1
    May 29th, 7:10 pm Thu 29/05/14 – Session 2

    What I need:

    May 29th, 7:40 pm Thu 29/05/14 – Session 1
    May 29th, 7:10 pm Thu 29/05/14 – Session 2

    May 31st, 11:33 am Sat 31/05/14 – Session 1
    May 31st, 10:40 am Sat 31/05/14 – Session 2
    May 31st, 9:38 am Sat 31/05/14 – Session 3

    Any ideas?

    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • You can do this using the edit_posts_orderby filter.

    I haven’t tested this code completely, but have tested the order by statemtn in MySQL and it does what you want.

    add_filter('posts_orderby', 'edit_posts_orderby');
    function edit_posts_orderby($orderby_statement) {
    	$orderby_statement = "DATE(post_date) DESC, TIME(post_date) ASC";
    	return $orderby_statement;
    }
    Thread Starter rperrett

    (@rperrett)

    Perfect, thank you!

    I just realized I had the order reversed. You want:

    DATE(post_date) ASC, TIME(post_date) DESC

    Thread Starter rperrett

    (@rperrett)

    Yep I realised that too, forgot to add it in my comment. Thanks for your fast reply.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Orderby date only not time’ is closed to new replies.