wp_reset_postdata() doesn't work
-
I’ve used the second-last example showed here:
https://github.com/scribu/wp-posts-to-posts/wiki/each_connectedThe 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!!!
————————————————–
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘wp_reset_postdata() doesn't work’ is closed to new replies.