WordPress.org

Ready to get started?Download WordPress

Forums

Query posts by category ~ not working (9 posts)

  1. sales@4bco.com
    Member
    Posted 3 years ago #

    I'm trying to query the posts by category

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

    However, what it puts out seems totaly random....The numbers are the category ID & theater is the category name....

    # Sucker Punch

    * Theater 4

    17March 22, 2011

    # Limitless

    * Theater 3

    16

    # The Lincoln Lawyer

    * Theater 2

    15

    # Diary of a Wimpy Kid 2

    * Theater 1

    14

    # Red Riding Hood

    * Theater 6

    19

    # Paul

    * Theater 5

    18

    # Mars Needs Moms

    * Theater 4

    17March 18, 2011

    # Paul

    * Theater 1

    14

    # The Adjustment Bureau

    * Theater 6

    19

    # Battle: Los Angeles

    * Theater 3

    16

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    There's no orderby=category in query_posts.

  3. sales@4bco.com
    Member
    Posted 3 years ago #

    Well, that would explain why it doesn't work.... What code should I use to get it to order by the category.... I just saw that code in lots of places on this site, guess that why other people had problems too.

  4. esmi
    Forum Moderator
    Posted 3 years ago #

  5. sales@4bco.com
    Member
    Posted 3 years ago #

    Yes, I've read that & found no reference on how to make the posts sort by category

  6. esmi
    Forum Moderator
    Posted 3 years ago #

    That's because there isn't an option to order by category. The only way to do this would be to have multiple Loops - each calling one category at a time.

  7. sales@4bco.com
    Member
    Posted 3 years ago #

    Well, I need to query posts not in category 12. They need to be sorted by date first, then by category. Can you give me any more specifics on how to make this happen?

  8. esmi
    Forum Moderator
    Posted 3 years ago #

    That is going to take a lot of work. You'd need to grab the results of the standard query (as opposed to displaying it) and then start looping through it to pull out/display posts from a specific category. Then repeat for every category that you want to display.

  9. sales@4bco.com
    Member
    Posted 3 years ago #

    Ok...I have my code narrowed down & closer to what I want. Hoping someone can help me finalize it

    Need to first query the posts to only pull in those whose movieStartDate value is less than or equal to today....then have it loop through the code to sort by category

    ****query_posts (meta_key='movieStartDate'&meta_value<=time())

    [Code moderated as per the Forum Rules. Please use the pastebin]

Topic Closed

This topic has been closed to new replies.

About this Topic