WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 am querying and ordering posts with this code but my theme adds the custom field (cb_vote_nb_vote) only if someone clicks the "vote" button, since I am doing a listing, posts created without that custom field under a specific category must also be displayed. How do I achieve that?

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;
share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.