Title: wp_reset_postdata() doesn&#039;t work
Last modified: August 21, 2016

---

# wp_reset_postdata() doesn't work

 *  [Marco Panichi](https://wordpress.org/support/users/marcopanichi/)
 * (@marcopanichi)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/wp_reset_postdata-doesnt-work/)
 * I’ve used the second-last example showed here:
    [https://github.com/scribu/wp-posts-to-posts/wiki/each_connected](https://github.com/scribu/wp-posts-to-posts/wiki/each_connected)
 * The only difference is that I’ve put the **the_title** output after echoing the
   connected posts. So my code is:
 *     ```
       <?php
       $my_query = new WP_Query( array(
       	'post_type' => 'movie'
       ) );
   
       p2p_type( 'movies_to_actors' )->each_connected( $my_query, array(), 'actors' );
   
       p2p_type( 'movies_to_locations' )->each_connected( $my_query, array(), 'locations' );
   
       while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
   
       	<?php
       	// Display connected actors
       	echo '<p>Actors:</p>';
   
       	foreach ( $post->actors as $post ) : setup_postdata( $post );
       		the_title();
   
       		...
       	endforeach;
   
       	wp_reset_postdata();
   
       	// Display connected locations
       	echo '<p>Filming locations:</p>';
   
       	foreach ( $post->locations as $post ) : setup_postdata( $post );
       		the_title();
   
       		...
       	endforeach;
   
       	wp_reset_postdata();
       	?>
   
       	<?php the_title(); ?>
   
       <?php endwhile; ?>
       ```
   
 * The problem is that all the posts after the first one show me the title of the
   first post:
 * ————————————————–
    Actors: actors of post title n.1 Locations: locations of post
   title n.1 TITLE n.1 ————————————————– Actors: actors of post title n.2 Locations:
   locations of post title n.2 TITLE n.1 **_<<<— WRONG!!!_** ————————————————–
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [ancawonka](https://wordpress.org/support/users/ancawonka/)
 * (@ancawonka)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/wp_reset_postdata-doesnt-work/#post-3828792)
 * Wow, that’s an interesting problem. At first glance it seems like it should work,
   though it’s kind of hard to understand what’s going on.
 * What have you tried to do to debug it?
 * Try doing a var_dump($post) in addition to the_title() after the second wp_reset_postdata().
   Is it going back to the original post int the loop?
 * What happens if there are three or four titles? Does it go back to the previous
   one, or to the first one?
 *  [mfrerebeau](https://wordpress.org/support/users/mfrerebeau/)
 * (@mfrerebeau)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/wp_reset_postdata-doesnt-work/#post-3828910)
 * J’ai le même souci sur l’interface d’admin (édition d’un CPT…)
    La solution trouvée
   a été d’extraire les données de ma query sans passer par les variables globale(
   sans utiliser the_post ou setup_postdata) :
 *     ```
       <select name="mf_toom_series_link" id="mf_toom_series_link">
               <option value="" ><?php _e( 'Série de cet épisode', 'mf_toom_series' ) ?>  </option>
               <?php $series_list = new WP_Query( array( 'post_type' => 'toom_serie', 'post_status' => 'publish', 'posts_per_page' => -1 ) ); ?>
               <?php foreach( $series_list->posts AS $serie ) : ?>
                   <option value="<?php echo $serie->ID ?>" <?php if( $mf_toom_series_link == $serie->ID ) : ?>selected="selected"<?php endif?> ><?php echo $serie->post_title ?> </option>
               <?php endforeach; ?>
           </select>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wp_reset_postdata() doesn't work’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

## Tags

 * [wp_reset_postdata](https://wordpress.org/support/topic-tag/wp_reset_postdata/)

 * 2 replies
 * 3 participants
 * Last reply from: [mfrerebeau](https://wordpress.org/support/users/mfrerebeau/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/wp_reset_postdata-doesnt-work/#post-3828910)
 * Status: not resolved