3

Is there any possible way to sort a new Wordpress post query by the title, but numerically instead of alphabetically?

I have some titles that have a lot of the same name alphabetically, then have a number afterwords, so of course for example Wordpress is putting title12 ahead of title1. Since each category has a few dozen titles like this to sort, getting the client to use Wordpress' sort order isn't a viable option.

Any thoughts? All I could find with default Wordpress functionality is sorting custom fields numerically, but not titles.

joren
  • 1,135
  • 2
  • 11
  • 22

1 Answers1

0

You simply just need to modify the query using either query posts:

query_posts('orderby=title&order=ASC');

Or create a whole new query using WP_Query:

$query = new WP_Query( array ( 'orderby' => 'title', 'order' => 'ASC' ) );

Wordpress figures out the ordering and does alpha then numeric sorting similar to the php func natsort I believe.

jonstuebe
  • 35
  • 4