2

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; ?>
3

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.

  • 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
1

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

$_GET['gdsr_sort'] = 'rating';
$_GET['gdsr_order'] = 'desc';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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