Title: $custom_query-&gt;current_post not working!?!?
Last modified: August 22, 2016

---

# $custom_query->current_post not working!?!?

 *  [malyutad](https://wordpress.org/support/users/malyutad/)
 * (@malyutad)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/custom_query-current_post-not-working/)
 * Hi everyone. I am designing a theme for WordPress and I need to create custom
   $wp_query calls in order to load in different post formats in different parts
   of the website. I write the following code:
 *     ```
       <?php
       $args = array(
          'post_type'=> 'post',
          'tax_query' => array(
          array(
             'taxonomy' => 'post_format',
             'field' => 'slug',
             'terms' => array( 'post-format-aside' )
          )
          )
       );
       $the_query = new WP_Query($args);
       ?>
   
       <?php if ( $the_query->have_posts() ) : ?>
   
       <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       <?php
          get_template_part( 'content-custom-posts', get_post_format() );
       ?>
       <?php endwhile; ?>
       ```
   
 * My problem is that in the content-custom-posts.php I do a check
 *     ```
       if($the_query->current_post == 0){...}
       else {...}
       ```
   
 * However, for some reason even though the while loop loops through all my posts,
   the expression above ALWAYS evaluates to true, as if the current_post is not 
   incrementing. I echoed $the_query->current_post and it gives back 0 1 2 3 4 …
   if I put it right before the get_template_part in the first code above, but DOES
   NOT RETURN ANYTHING if I echo it from within content-custom-posts.php
 * I searched all over the web and I cannot find a solution to my problem. Is my
   wp_query wrong for some reason? Because it works with $wp_query (default) but
   I need to do custom queries…
 * Thank you!

Viewing 1 replies (of 1 total)

 *  Thread Starter [malyutad](https://wordpress.org/support/users/malyutad/)
 * (@malyutad)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/custom_query-current_post-not-working/#post-5177230)
 * UPDATE : I just checked and in fact if I change the name $the_query to $wp_query,
   keeping all the arguments the same, it works. What is going on!? Why is the query
   variable name ($the_query) stopping my code from working?

Viewing 1 replies (of 1 total)

The topic ‘$custom_query->current_post not working!?!?’ is closed to new replies.

## Tags

 * [index](https://wordpress.org/support/topic-tag/index/)
 * [number](https://wordpress.org/support/topic-tag/number/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [malyutad](https://wordpress.org/support/users/malyutad/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/custom_query-current_post-not-working/#post-5177230)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
