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

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:

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:



Want to learn how to develop a site without knowing how to code?

PHP can sometimes be very daunting! Well there's a plugin out there that allows you to create complex WordPress sites, without knowing how to code! Learn more about the Toolset Plugins

p.s. there's a Genesis Course also available.


    • 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.

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

      • 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.

          • 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.

  1. 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?

    • 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.

    • 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.

      • 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?

        • 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:

  2. 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.

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

      • 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’

  3. Ö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.

  4. says

    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?

  5. 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.

  6. 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.

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

    • 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 *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>