Connection between 3 post types?
-
Hi, I have a site with 3 post types; ‘Contributor’, ‘Book’ and ‘Post’. I’ve set it up so a user can connect a Book to a Contributor and a Contributor to a Post. I’ve got it working so that on a Book page all the connected Contributors are listed and other Books by the same Contributor are listed. On a Contributor page all the Books and Posts by that Contributor are listed.
What I want is for a user to be able to connect a Contributor to a Post and then on a Book page list all Posts that are connected to any Contributors connected to that book.
So basically a Book page lists the connected Contributors, other Books by that Contributor(s) AND ALSO any blog Posts by that Contributor(s).
Is this possible with this plugin? Or should I be looking at another method? My code is below. Thanks!
<!-- Linked contributors --> <?php // Find connected Contributors $connected = new WP_Query( array( 'connected_type' => 'books_to_contributors', 'connected_items' => get_queried_object(), 'nopaging' => true, ) ); // Display connected Contributors if ( $connected->have_posts() ) : ?> <h3>Contributors:</h3> <ul> <?php while ( $connected->have_posts() ) : $connected->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php // Prevent weirdness wp_reset_postdata(); endif; ?> <!-- Connected Books by same Contributors --> <?php // Find connected Books $related = p2p_type( 'books_to_contributors' )->get_related( get_queried_object() ); // Display connected Books if ( $related->have_posts() ) : ?> <h3>Related Books:</h3> <ul> <?php while ( $related->have_posts() ) : $related->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php // Prevent weirdness wp_reset_postdata(); endif; ?>
The topic ‘Connection between 3 post types?’ is closed to new replies.