Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.