Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This correctly sort posts by thumbs vote (GD star rating plugin):

<?php query_posts('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2&post_parent='.$post->ID); ?>
<?php while ( have_posts() ) : the_post(); ?>
    <h2><?php  the_title(); ?></h2>
    <?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

But this doesn't sort them at all:

        <?php $custom_posts = new WP_Query(); ?>
        <?php $custom_posts->query('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2&post_parent='.$post->ID); ?>
        <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?>
            <div class="content-block-2">
                    <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?>
                    <?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?>
                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
            <?php the_content(); ?>

            </div>
        <?php endwhile; ?>
share|improve this question

2 Answers 2

up vote 3 down vote accepted

It seems GD Star Rating uses get_query_var() to read query variables, which only reads this global $wp_query variable. query_posts() overwrites the global $wp_query variable, so it works there, but creating a new WP_Query (which is a good practice) will not work. You should contact the plugin author and ask for a fix.

share|improve this answer
    
Still not fixed as of latest version 1.9.10. Thanks for the info, Jan. –  Tom Auger Aug 2 '11 at 18:12
    
I hardcoded the get parameters to always sort, maybe that helps somebody else:add_action("init", "MuviceInit",1); function MuviceInit() { global $muvice; $_GET["gdsr_sort"]='thumbs'; $_GET["gdsr_order"]='desc'; $muvice = new Muvice(); } –  Cilvic Mar 31 '12 at 13:17

Cilvic's advice works for me. Just set the GET parameters before using WP_Query.

$_GET['gdsr_sort'] = 'rating';
$_GET['gdsr_order'] = 'desc';
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.