[Plugin: Post2Post] Problem with multiple each_connected
-
Generally Post2Post is a life-saver, but today I’ve been stuck on the following:
I have a post type “Movie,” and I need to display a list of connected post type “Scene.” With each Scene, I need to display connected post types “Director” and “Performer.”
I’ve tried all of the methods on https://github.com/scribu/wp-posts-to-posts/wiki/each_connected and each presents a similar problem: It will return Scenes, and it will return the first connected post type below that. The second will generate an error. For the preferred method (each_connected), the error is: Invalid argument supplied for foreach()… on the line of the second foreach() call. Doesn’t matter which is second.
Here’s my current code. I’ve tinkered with it all day, and even switched to the nested WP_Queries method (that gave me a “no direction(s) error… again, on the second query only).
<?php // Find connected posts $scenes = new WP_Query( array( 'connected_type' => 'movie_to_scene', 'connected_items' => get_queried_object(), 'nopaging' => true ) ); p2p_type( 'performer_to_scene' )->each_connected( $scenes, array(), 'joy_performer' ); p2p_type( 'director_to_scene' )->each_connected( $scenes, array(), 'joy_director' ); if ( $scenes->have_posts() ) : while ( $scenes->have_posts() ) : $scenes->the_post(); ?> <div class="row-fluid"> <div class="span3"> </div> <div class="span9 entry-content"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <!-- scene info --> <?php foreach ( $post->joy_performer as $post ) : setup_postdata( $post ); the_title(); endforeach; wp_reset_postdata(); foreach ( $post->joy_director as $post ) : setup_postdata( $post ); the_title(); endforeach; wp_reset_postdata(); ?> <!-- /scene info --> </div> </div> <?php endwhile; wp_reset_postdata(); endif; ?>
- The topic ‘[Plugin: Post2Post] Problem with multiple each_connected’ is closed to new replies.