Continuous listing from a custom field

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:

query_posts('cat=47meta_key=cb_vote_nb_voteorderby=meta_valueorder=DESC');

        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?

Topic listing query posts Wordpress

Category Web


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;
wp_reset_postdata();

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.