Home > Code, General, PHP, Wordpress > WordPress: Custom Post Order

WordPress: Custom Post Order

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);

   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); ?>
Categories: Code, General, PHP, Wordpress Tags: ,
  1. No comments yet.
  1. No trackbacks yet.