query_posts ORDERBY not actually ordering properly
-
I have a page (using a page template with no loop) that fetches all posts from category 39. There are 11 child categories in category 39 that automatically get pulled in with this code:
<?php query_posts("cat=39&showposts=-1&orderby=category"); ?>
I need to order them by category coming in because the next bit of code on my page spits them out with category headings like this where the category title is only shown once on the page and all posts in that category are displayed under it.
CATEGORY 1 NAME
Post Name
Post Name
Post NameCATEGORY 2 NAME
Post Name
Post Name
Post NameCATEGORY 3 NAME
Post Name
Post Name
Post Name<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php setup_postdata($post); $title = get_the_title(); $category = get_the_category(); $category = $category[0]->cat_name; ?> <?php if ($category != $previous_category) : ?> <?php if($ul_open == true) : ?> </ul> <?php endif; ?> <h5 class="spitcat-title"><?php echo $category; ?></h5> <ul class="spitposts"> <?php $ul_open = true; ?> <?php endif; ?> <?php $previous_category = $category; ?> <li>Stuff</li> <?php endwhile ?> </ul> <?php endif; ?>
This solution WAS working in my local MAMP installation, but when I moved the data and the theme to the web server, it no longer worked. The order of the posts is NOT coming in by category because now I’m getting this, a situation where the category title is showing up multiple times on the page.
CATEGORY 3 NAME
Post NameCATEGORY 1 NAME
Post NameCATEGORY 2 NAME
Post Name
Post NameCATEGORY 1 NAME
Post NameCATEGORY 3 NAME
Post Name
Post Name
Post NameI’m confused as to why the ORDERBY suddenly isn’t working – it works in my local instance – so any insights into this would be great. A better solution like a function I can drop in my functions.php would be better but I was not able to find one.
- The topic ‘query_posts ORDERBY not actually ordering properly’ is closed to new replies.