Treehouse: Grow your CSS skills. Land your dream job.

WordPress query_posts ~ Need help getting it to work properly

  • # March 23, 2011 at 2:58 pm

    I need to query posts so that they sort first by date with the oldest appearing first, then by category with the lowest number appearing first. I can’t get anything to work. Please help!

    < ?php query_posts( 'posts_per_page=24&cat=14,15,16,17,18,19&orderby=date&order=ASC&orderby=category&order=DESC' ); ?>

    When I use simply

    < ?php query_posts( 'cat=-12&orderby=category&order=DESC' ); ?>

    The order seems totally random, the categories are not in order at all

    Site w/ problem

    # March 23, 2011 at 3:40 pm

    What do you mean order by date and then order by category? You can’t have two different orders working at the same time.

    # March 23, 2011 at 7:00 pm

    It sort of sounds like you’re trying to create separate lists of posts – one list for each category – and each list is ordered by date.

    Maybe you can elaborate on what you’re trying to accomplish? That seems a bit strange to me.

    # March 28, 2011 at 9:16 pm

    Well, I was finally able to solve the problem….What I was trying to do was to “group” the posts by date & then sort those by category…or theater if you looked at the site.

    The idea was to show all of the movies showing this week together first in order by theater b/c theater 1, 2, etc….also meant it was the newest movie.

    I was able to solve the problem by switching up the requirements for the site & doing something different than what the owner had asked for, but something that works completely better…well, b/c it works!

    Cinema Site Finished Product

    Let me know what you think.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.