Title: Sorting Posts By Comment Count NOT WORKING
Last modified: August 24, 2016

---

# Sorting Posts By Comment Count NOT WORKING

 *  Resolved [creativitykills](https://wordpress.org/support/users/creativitykills/)
 * (@creativitykills)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/sorting-posts-by-comment-count/)
 * Is there a reason why posts dont get sorted by comments? I have tried and tried
   just not working. I have the Jetpack comments enabled so could this be the problem??
 * I have pasted the custom page template so you guys can see because i’m stomped
 *     ```
       <?php
       /*
         Template Name: Popular Posts
       */
   
       get_header();
   
       $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
   
       // WP_Query arguments
       $args = array (
       	'post_type'              => array('post'),
       	'pagination'             => true,
       	'posts_per_page'         => '12',
       	'order_by' 				 => 'comment_count',
       	'order'					 => 'DESC',
       	'paged'					 => $paged,
       	'ignore_sticky_posts'	 => true,
       );
   
       $orig_post = $post;
   
       // The Query
       $wp_query = new WP_Query( $args );
   
       // The Loop
       if ( $wp_query->have_posts() ): ?>
       <div class="articles-list">
       	<div class="list-em">
       		<div id="articles-container">
       		<?php while ( $wp_query->have_posts() ): $wp_query->the_post(); ?>
   
       		<?php
       			/* Include the Post-Format-specific template for the content.
       			 * If you want to override this in a child theme, then include a file
       			 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
       			 */
       			get_template_part( 'content', get_post_format() );
       		?>
   
       		<?php endwhile; ?>
   
       		<?php $post = $orig_post ?>
   
       		<?php the_posts_navigation(); ?>
   
       		</div>
       	</div>
       </div>
       <?php else: ?>
   
       	<?php get_template_part( 'content', 'none' ); ?>
   
       <?php endif; ?>
   
       <?php wp_reset_postdata() ?>
       <?php // wp_reset_query() ?>
       <?php get_footer() ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Bill](https://wordpress.org/support/users/chubbycrow/)
 * (@chubbycrow)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/sorting-posts-by-comment-count/#post-5984303)
 * Try changing `'order_by'` to `'orderby'`.
 *  Thread Starter [creativitykills](https://wordpress.org/support/users/creativitykills/)
 * (@creativitykills)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/sorting-posts-by-comment-count/#post-5984328)
 * Thanks. Solved it.
 *  [Bill](https://wordpress.org/support/users/chubbycrow/)
 * (@chubbycrow)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/sorting-posts-by-comment-count/#post-5984334)
 * Glad you got it worked out.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Sorting Posts By Comment Count NOT WORKING’ is closed to new replies.

## Tags

 * [custom page template](https://wordpress.org/support/topic-tag/custom-page-template/)
 * [sort posts](https://wordpress.org/support/topic-tag/sort-posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Bill](https://wordpress.org/support/users/chubbycrow/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/sorting-posts-by-comment-count/#post-5984334)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
