Changing Sort Order in StudioPress Themes


Hit a rather irksome problem recently in developing a WordPress website on the StudioPress Genesis framework. I could not find anywhere to change the default sort order (Newest to Oldest by time of publication). Nothing in the functions. Nothing I could find in the lib settings. Nothing in the theme options (which I believe should be changed).

Finally, after hearing back from the developers and having them point me to a nice, clean function for supposedly resolving this, I gave it a try. It had the unfortunate side effect of knocking out my static homepage because it went into the loop, thought the homepage had a loop, and decided to simply sort all the posts in the database into that page. At least it showed them in the specified order.

Thankfully, I came up with a quick way to resolve this pesky problem. All you have to do is wrap the function with a check to determine if it is a page. Here’s the code:

/** Order Posts Alphabetically **/
add_action('genesis_before_loop', 'child_before_loop');
function child_before_loop () {
if ( !is_page() ) {
global $query_string;
query_posts($query_string . "&order=ASC&orderby=title");

Here’s the Step-by-Step:

  1. Determine how and what you want to sort. The code above shows an ascending alphabetical order by Title. If you wanted to show an ascending by time, you would eliminate the &orderby=title portion of the string. To show a random set, use &order=rand
  2. Specify any limitations on where you want this to use the specified order of posts. With no limitations placed, it will consider the homepage to have a loop and will likely include all Posts in that loop. The code above specifies that this should only be applied to non-page instances.
  3. Add your code to the functions.php file of your child theme. This can be done through the Appearance > Editor area by choosing Theme Functions.
  4. Update and check your site

Nothing too complex. Hope it works for you too.

3 thoughts on “Changing Sort Order in StudioPress Themes

  1. Thanks for saving my butt with this! It might be helpful for users to know that if they use

    query_posts($query_string . “&order=ASC”);

    It will work based on date only. When my posts were numbered 1, 2 , 3 …10, 11. I ended up with 1, 10, 11, 2, 3….

    Anyhoo… thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.