Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress: get current_post index number in WHILE loop

How to get current post index number inside WHILE loop?

$index_query = new WP_Query( array( 'post_type' => 'post', 'orderby' => 'modified', 'posts_per_page' => '-1', 'order' => 'DESC' ) );
while ( $index_query->have_posts() ) : $index_query->the_post();

    // echo current post index number

endwhile;

Have tried with the following, but no result.

$index_query->post->current_post;

Any suggestions much appreciated!

like image 526
Iladarsda Avatar asked Sep 13 '12 18:09

Iladarsda


2 Answers

You should use

$index_query->current_post;

http://codex.wordpress.org/Class_Reference/WP_Query#Properties

like image 99
soju Avatar answered Nov 19 '22 22:11

soju


I can get by using this code

$wp_query->current_post
like image 30
adenizc Avatar answered Nov 19 '22 22:11

adenizc