Don’t Worry, You’re In The Right Place
A lot of these posts were originally on So if you found them through search engines or clicking around, this is their new home :). Enjoy!

How to reverse the post order using the Genesis Framework

OK, first let me say “WOW”.  Trying to find this information literally took me over an hour but I finally pieced it all together.  You would think that the solution would be so easy to find.  I just wanted to reverse the order output.

I found a ton of different ways to do it, the only problem was, NONE OF THEM WORKED!!!

But I figured it out finally… so here’s the code =)

[code language=”php”]
add_action(‘genesis_before_loop’, ‘child_before_loop’);
function child_before_loop () {
global $query_string;
query_posts($query_string . "&order=ASC");

You can actually edit any part of this code once you know the variable to put in.

For example if you wanted it in ascending order based on the title, you would do something like this:

[code language=”php”]
add_action(‘genesis_before_loop’, ‘child_before_loop’);
function child_before_loop () {
global $query_string;
query_posts($query_string . "&order=ASC&orderby=title");

So in conclusion you can pretty much edit the entire query string based on this code. Thank GOD!!

Oh yeah… and the best part is:



About the Author
What's UP! This is my site, I write 99% of the articles on here. I'm also the owner of I help out a lot of developers and designers getting into the web game. Helping is fun for me, so feel free to ask me any questions! I've made courses and have a membership as well to help get you on your feet!

39 comments on How to reverse the post order using the Genesis Framework

  1. This doesn’t seem to work for me. It runs the query in ASC by title and the page runs the loop a second time as well. Something is amiss.

    1. Jonathan says:

      It definitely shouldn’t be sorting by title unless there’s something else in the query. Also, if it’s a new loop, make sure to remove the old one first. If you want, paste your code and I’ll take a look at it.

  2. Laeh says:

    Thank you! Was pointed here via Studiopress. Exactly what I needed.

  3. Kim says:

    this is working global. What would I write if I only wanted this to be true for one of my categories?

    1. Jonathan says:

      you would just have to add “cat=45′, 45 being the id of the category you would want to include, in your query string. So query_posts($query_string . “&order=ASC&orderby=title&cat=45”);

      1. Steve Horn says:

        If I’m trying to affect only a category and add what you show above, it works great for that category but then all other categories can’t be found and bring up a “Sorry, no content matched your criteria” message.

        1. Jonathan says:

          Well that definitely shouldn’t be happening as the code itself is only changing the order of what’s already being out put, not the output itself.

          In any case, I haven’t had a chance to update the post with more recent code, but check out Rob’s revision of it:

          See if that helps, if not, it may be another issue.

          1. Jodi says:

            I’m looking for the same solution. I have one category I want to show in reverse order and this code works, but for other category pages, it now says, “Sorry, no content matched your criteria.” The link for Rob’s revision is not working.

  4. Kyle P says:

    This worked great, only thing is that it replaced my static home page with the news page that I had used it for. Any idea why or how I can get my static home page back to normal, but still have this work on my posts page?

    1. SureFireWeb says:

      it definitely shouldn’t have replace anything… If you want to use it on a specific category then you should use the “cat=45” argument. take a look @kim comment below and see if that will work for you.

  5. Mark A says:

    What if you simply wanted it to display pages first and post last, regardless of chronological order?

    1. SureFireWeb says:

      I guess I would have to see an example. Posts and Pages are different, not sure what situation would warrant you to display both… I’d love to help if you can elaborate.

      1. Mark A says:

        We would like to have people use the search box to find product pages based on their query rather than post. Currently both posts and pages are displayed but the pages are at the end… Is there a way to write the code to simply display site pages as search results?

        1. SureFireWeb says:

          Hi Mark, I think the solution to this is a little more in depth then just adding a little piece to the query. I’m sure you can add arguments to the query and use post_type pages, but your solution seems to be more in the search functionality. I would try to find an advanced search plugin or something similar. I think views would work great for that. Here’s a link:

  6. Steve Horn says:

    This works for me for title and for date either ascending or descending. Is it possible to get a random order display? I have one client who wants equitable display order and I can’t figure that out.

    1. Steve Horn says:

      I think this works but not sure. Do you know or do you know how I could verify?

      function child_before_loop () {
      global $query_string;
      query_posts($query_string . "&order=ASC&orderby=rand");

      1. SureFireWeb says:

        that looks exactly right. I would just put it in your functions file along with the rest of the code. If it doesn’t work, remove it, but it should be a quick check. Also, don’t think you need “order=ASC” if your using ‘rand’

  7. Özgür Oktay NAR says:

    Dear Sir,

    > How do i sort older posts header A to Z ?

    > Forexample;

    > i have 300 more posts from ” A” category.

    > İ want to make a landing page to show vizitors , category “A ” index page and

    > sort posts header A to Z.

    > Thank you.

    1. SureFireWeb says:

      Hi, take a look at the wordpress codex for different ways to sort your query.

  8. Thank you for sharing this Great Post… I was really having trouble with sorting posts in genesis themes and tried many times but failed.. How do you this in category pages only?

    1. SureFireWeb says:

      You can get the category ID and use a wordpress conditional tag to target that specific category.

  9. Ajax Woolley says:

    Worked for me, thanks for sharing!

    1. SureFireWeb says:

      Your very welcome!

  10. Lexy Kassan says:

    I also encountered the issue where the home page resorted to a news page. Fixed by adding a if ( !is_page() ) wrap around it. Now works like a charm.

    1. Jonathan says:

      Thanks for the solution Lexy!

  11. Vi Wickam says:

    That did the trick. Thanks for posting!

  12. hcg says:

    Great writing. My thanks for posting this. I’ll come here to find out more and tell my coworkers about this site.

  13. luke dyer says:

    How do you sort posts by comment count?

    1. Jonathan says:

      on orderby use the statement “comment_count” without the quotes. orderby=comment_count

  14. Charlie says:

    Hi, I’ve tried using this with my child theme which only has a style.css and a function.php files. My function.php is very empty but when I copied and pasted the oldest post first code, it made my site crash.

    I’m probably doing something very silly but help would be appreciated.

  15. Charlie says:

    Never mind got it working

    1. Jonathan says:

      =) Great!

  16. Andy Jobben says:

    I made it like this, but it tells me he cant find any matches.

    // change order category
    add_action(‘genesis_before_loop’, ‘child_before_loop’);
    function child_before_loop () {
    global $query_string;
    query_posts($query_string . ““&order=ASC&orderby=post->ID&cat=7”);

    1. Jonathan says:

      Hi Andy, You have some extra parameters in there. First, make sure that cat=7 is definitely the category you’re looking to sort, also, you have post->ID but you don’t have the global variable set. You’ll have to add global $post to the beginning of your functions and use $post->ID with the dollar sign.

Leave a Reply

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

Scroll to top