WordPress.org

Support

Support » How-To and Troubleshooting » Custom sorting of wp_query?

Custom sorting of wp_query?

  • 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom sorting of wp_query?’ is closed to new replies.
Skip to toolbar