I've created a custom query to pull all posts from a custom post type, ordered by comment count. It's your run-of-the-mills custom query:
<?php $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wposts.post_status = 'publish' AND wposts.post_type = 'Tutorials' ORDER BY wposts.comment_count DESC "; $tutorialposts = $wpdb->get_results($querystr, OBJECT); ?> <?php if ($tutorialposts): ?> <?php global $post; ?> <?php $i = 0; ?> <?php foreach ($tutorialposts as $post): ?> <?php $i++; ?> <?php setup_postdata($post); ?> <h2><?php echo $i ?>: <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <?php endforeach; ?> <?php endif; ?>
It has a little code added to it to number the posts. But I took this code out and the same problem persisted.
It actually does what it's supposed to do! In fact, it's so excited about doing what it's supposed to do, that it does it twice.
Also if anyone could tell me how to parse this code so it only shows the top 10 posts retrieved by the query that would be excellent. But I could probably figure that out on my own, that's just me being kind of lazy.
I really just need to know why it's pulling each post and displaying it twice o.0