The MU forums have moved to WordPress.org

wp_query orderby not working in custom loop (2 posts)

  1. roytanck
    Member
    Posted 14 years ago #

    I posted this message in the regular WP forum earlier, but it seems this is MU-related. Sorry for cross-posting.

    I'm building a theme for a WPMU 2.7.1 hosted blog. The client wants an archive of all posts (in the same blog) 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; ?>

    I've echoed the query string and it looks OK to me.

    showposts=-1&orderby=rand&order=DESC

    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.

    On non-MU WP 2.8.4 sorting works fine.

    Does anyone have any idea what could be wrong here? Any known issues with 'orderby' in older WPMU versions?

  2. selcyis
    Member
    Posted 14 years ago #

    Hello Roytanck,

    I kinda having the same issue. Do u think you can help me with my jquery conflit?
    I think its a easy fix but not sure how to approach this issue. It seems you would know more then others on the function.

    If interested, i will post the issue.
    Thanks;)

About this Topic

  • Started 14 years ago by roytanck
  • Latest reply from selcyis