I have posts with custom fields called "cb_vote_nb_vote" which holds the vote count for every post, what I want to do is let's say posts under A category will be listed based on vote count, I do that and show numbers with:


        if(have_posts()) :
        while(have_posts()) : the_post() ; echo "<div id='listing'>"; echo $wp_query->current_post +1; echo "</div>";  ?>

but the problem here is when you go to the new page it starts from number 1 obviously. How can I achieve that so the listing continues from the previous page?

1 Answer 1


First of all, please don't use query_posts, but a new WP_Query.

Outpu count based on page is just a matter of a simple arithmetic operation using current page number and posts per page number.

global $wp_query;
$paged = $wp_query->get('paged') ? : 1;
$posts_per_page = 10; // feel free to change this
$args = array(
  'cat'            => 47,
  'meta_key'       => 'cb_vote_nb_vote',
  'orderby'        => 'meta_value',
  'order'          => 'DESC',
  'paged'          => $paged,
  'posts_per_page' => $posts_per_page
$query = new WP_Query( $args );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();

  $current_order = ( $query->current_post + 1 ) + ( $posts_per_page * ( $paged - 1) );
  echo 'Current post order is :' . $current_order;

endwhile; endif;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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