[Plugin: Posts 2 Posts] Again, have_posts() error
-
hi,
first of all i want to say this a really great plugin!
i can manage all my connections perfectly in the admin backend but dont get them displayed on my custom-single.php.
i have this in my functions.php
function my_connection_types() { // Make sure the Posts 2 Posts plugin is active. if ( !function_exists( 'p2p_register_connection_type' ) ) return; p2p_register_connection_type( array( 'name' => 'show_artist_label', 'from' => 'shows', 'to' => array( 'artists', 'labels' ), 'cardinality' => 'one-to-many', 'title' => array( 'from' => 'Artist and Labels', 'to' => 'Shows' ) ) ); } add_action( 'init', 'my_connection_types', 100 );
and this in my custom-single.php:
<?php // Find connected posts $connected = new WP_Query( array( 'connected_type' => 'show_artist_label', 'connected_items' => get_queried_object_id(), ) ); // Display connected pages if ( $connected->have_posts() ) : ?> <h3>Related pages:</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; ?>
when displaying the custom-single.php i get the following error:
Fatal error: Call to a member function have_posts() on a non-object in …
any ideas what i’m doing wrong?
thanks in advance for your help!
best,
christoph
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘[Plugin: Posts 2 Posts] Again, have_posts() error’ is closed to new replies.