WordPress.org

Ready to get started?Download WordPress

Ideas

Independent ASC/DESC in multiple ORDER BY statement.

  1. leemon
    Member

    12345

    WP_Query supports ordering results by multiple columns, but does not currently support independent ASC/DESC declarations on those columns. Instead, it concatenates the ORDER and ORDER BY statements together.

    In some cases, it would be beneficial to independently set the order for these columns. An example offered on WP-Hackers:

    I have a situation where I want to order a list of post both by author and date using WP_Query which isn't a problem since 'orderby' lets me do that. But I want the author part sorted ascending and date part sorted descending.

    A normal MySql statement would end with ORDER BY author ASC, date DESC.

    We should extend WP_Query to allow users to set their ordering parameters independently. This should be done in such a way as to not break backwards compatibility.

    http://core.trac.wordpress.org/ticket/17065

    Posted: 1 year ago #
  2. Simon
    Member

    12345

    It can be usefull, thx

    Posted: 1 year ago #
  3. prophecy2040
    Member

    12345

    I came across the need for this just the other day on two separate sites I was working on. I ended up having to hook into the posts_orderby filter and modify it for the certain instance I needed - so it was a lot more work than it should have been.

    With the more versatile uses of WordPress sites these days, the need arises to perform more complex queries to get the right data. And who wants to have to write their own custom query calls when WP_Query is so great and easy to use?

    I mainly just want to agree with extending the WP_Query class to allow for this functionality. With the great features like the meta_queries and the integration of the custom post type taxonomy - it just falls flat without the ability to sort the multiple columns independently.

    Don Fischer

    Posted: 1 year ago #
  4. Jac0bDaniel
    Member

    leemon!

    I was reading your post with the hope for some new information.

    The interesting thing here is that I have learned the new element of MySql statement of using ASC & DESC both in the single query, however you were talking about WP.

    That was a severe headache for me in my last project. And I have ended it over 2 different queries.

    Well, that project was finished but the info gained from you is useful for future project.

    Thanks for writing.

    Posted: 1 year ago #
  5. leemon
    Member

    12345

    Bummer! A patch for this was going to be included in 3.7, but now I see that someone pushed it to a Future Release ¬¬'

    Why?

    Posted: 11 months ago #
  6. leemon
    Member

    12345

    Apparently, someone added a patch for 4.0. I just hope it doesn't get pulled at the last minute.

    https://core.trac.wordpress.org/ticket/17065#comment:60

    Posted: 1 month ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    7 Votes
  • Status

    This idea is under consideration