WordPress: Custom Post Order
September 25th, 2009
No comments
I recently had a requirement for custom ordering on WordPress categories and thought that I would share how I did it.
All that is needed is this piece of code which essentially modifies the SQL statement being generated. Note that the argument assigned to orderby is the column name, hence it is case sensitive (I found out that ID breaks the naming conversion on the post table);
<?php
if (is_category(array($myCatId))){
query_posts($query_string . "&orderby=ID&order=DESC");
}
?>
Code needs to be placed before this line
<?php if (have_posts()) : while (have_posts()) : the_post(); update_post_caches($posts); ?>
Recent Comments