Get Great Web Design Tips, WordPress Development Help,
and Genesis Framework Tutorials!

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:

THIS WILL WORK ON ANY CHILD THEME!!!!!

Enjoy!

If you liked this post, say thanks by sharing it:

This Site Runs on the Genesis Framework

Genesis empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go. It's that simple - start using Genesis now!

Take advantage of the 6 default layout options, comprehensive SEO settings, rock-solid security, flexible theme options, cool custom widgets, custom design hooks, and a huge selection of child themes ("skins") that make your site look the way you want it to. With automatic theme updates and world-class support included, Genesis is the smart choice for your WordPress website or blog.

Comments

  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.

    • 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. Thank you! Was pointed here via Studiopress. Exactly what I needed.
    Laeh recently posted..Best Pillows for Side SleepersMy Profile

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

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

  4. 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?
    http://www.carylodge198.org
    Thanks!!!

    • 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. What if you simply wanted it to display pages first and post last, regardless of chronological order?

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

      • 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: http://surefirewebservices.com/go/wp-views

  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.

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

  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.

  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?

  9. Ajax Woolley says:

    Worked for me, thanks for sharing!

  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.

  11. That did the trick. Thanks for posting!

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

Trackbacks

  1. [...] 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 [...]

Speak Your Mind

*

CommentLuv badge

Before you post, please prove you are sentient.

what is 5 plus 9?