WordPress.org

Ready to get started?Download WordPress

Forums

Getting most commented posts of current category (1 post)

  1. liaaz
    Member
    Posted 3 years ago #

    I am trying the below to get the
    most commented posts of current category

    can you correct that where am I wrong ?

    <?php
    $cat_id = get_query_var('cat');
    $results = $wpdb->get_results("SELECT ID, comment_count FROM wp_posts WHERE post_type = 'post' && post_status = 'publish' && term_taxonomy.term_id=$cat_id ORDER BY comment_count DESC LIMIT 5");
    foreach ($results as $r):
    	query_posts(array('p' => $r->ID));
    	while (have_posts()):
    		the_post();
    ?>
    <!-- regular <b style="color: black; background-color: rgb(255, 153, 153);">wordpress</b> loop code goes here -->
    <?php endwhile; endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.