wp_query orderby not working in custom loop
-
I’m building a theme for a WPMU 2.7.1 hosted blog. The client wants an archive of all posts on every single post page, which is why I’m using wp_query to create a second loop. My problem is that the ‘orderby’ parameter seems not to work propery.
I use an $order var that can be either ‘date’, ‘author’, ‘rand’ or ‘title’. (This code also includes a fix I found that restores the old query that may not be needed here.)
<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $ascdesc = ( $order == 'title' || $order == 'author' ) ? 'ASC' : 'DESC'; $queryStr = 'showposts=-1&orderby='.$order.'&order='.$ascdesc; $wp_query->query($queryStr); ?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <!-- loop stuff --> <?php endwhile;?> <?php $wp_query = null; $wp_query = $temp;?>
Om my test install of WPMU 2.3.3 (which I need to keep at that old version to match another client install) it works OK, except for ‘rand’ which orders by date.
On the 2.7.1 install, no matter which order I select, posts are always ordered by date.
Does anyone have any idea what could be wrong here?
- The topic ‘wp_query orderby not working in custom loop’ is closed to new replies.