WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this custom loop:

<?php // Display the top ones
    $args = array(
        'post_type' => 'reply',
        'post_parent' => $post->ID,
        'r_sortby' => 'highest_rated',
        'r_orderby' => 'desc',
        'order' => 'DESC'

<?php query_posts( $args ); ?>

<div class="entry-list-top">

<?php while ( have_posts() ) : the_post(); ?>

    <h2 class="dark-title"><?php _e( 'Top Replies' ); ?></h2>

    <div class="topic-entry">
        <div class="topic-author">
            <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?>

        <div class="topic-content">
            <span class="topic-author-link"><?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?></span>
            <?php bbp_reply_admin_links(); ?>
            <span class="topic-post-date"><?php printf( __( '<span>%1$s</span> <span>at %2$s</span>', 'bbpress' ), get_the_date(), esc_attr( get_the_time() ) ); ?></span>
            <?php bbp_reply_content(); ?>

        <div class="tt-like-button">
            <?php if(function_exists('the_ratings')) { the_ratings(); } ?>



    <?php $most_voted[] = get_the_ID(); // get the id of the most voted post ?>

<?php endwhile; ?>

I would like to retrieve the number of posts (only in this loop). (The is another loop below).

Any suggestions?

share|improve this question
up vote 2 down vote accepted

Just count the number of returned posts of the first loop:


<?php query_posts( $args ); ?>


$posts = query_posts( $args );
$count = count($posts);
share|improve this answer
Sorry, where should I place that code? – janoChen Jun 28 '11 at 16:12
Thanks! Hope it wasn't a basic question. – janoChen Jun 28 '11 at 16:28

Your Answer


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.