WordPress.org

Ready to get started?Download WordPress

Forums

Custom sorting of wp_query? (3 posts)

  1. carrorcake
    Member
    Posted 4 years ago #

    I have a query that I need to use natsort on. I'm sorting my posts by titles, ascending and since they all are numerical, it looks very strange.
    E.g.,
    1,10,11,12,2,20,21.

    Does anyone have any ideas on how I could accomplish this?

  2. Darrell Schauss
    Member
    Posted 4 years ago #

    If you were using an actual SQL query you could use ORDER BY CONVERT(post_title, SIGNED)

    I wonder if it would work to put CONVERT(post_title, SIGNED) as the orderby argument in wp_query.

  3. MichaelH
    Member
    Posted 4 years ago #

    I wonder if it would work to put CONVERT(post_title, SIGNED) as the orderby argument in wp_query.

    You'd have to use wpdb for that, not the wp_query unless you setup some kind of filter.

Topic Closed

This topic has been closed to new replies.

About this Topic