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; 

We tried with the following, but there was no result.

 $index_query->post->current_post; 

Any suggestions that were highly appreciated!

+6
source share
1 answer

You have to use

 $index_query->current_post; 

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

+9
source

Source: https://habr.com/ru/post/925351/


All Articles