Title: [Plugin: Posts 2 Posts]  Again, have_posts() error
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Again, have_posts() error

 *  [hundstage](https://wordpress.org/support/users/hundstage/)
 * (@hundstage)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/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
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-again-have_posts-error/#post-2463603)
 * Unless there’s some other code between $connected = new WP_Query( … )`and`if (
   $connected->have_posts() )` that error doesn’t make any sense.
 * Are you sure `custom-single.php` is actually the file that’s loaded?
 *  Thread Starter [hundstage](https://wordpress.org/support/users/hundstage/)
 * (@hundstage)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-again-have_posts-error/#post-2463617)
 * hm, yes i’m sure, the error goes:
 * Fatal error: Call to a member function have_posts() on a non-object in /kunden/
   264270_70176/webseiten/wordpress/wp-content/themes/studior/single-shows.php
 * i’m using your basic usage example, just modified the connected_type
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-again-have_posts-error/#post-2463632)
 * Again, it’s not possible. You create an instance of the WP_Query class, which
   most definitely does have a `have_posts()` method.
 * Also, you said `custom-single.php` in your first post, but the error path says`
   single-shows.php`

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

The topic ‘[Plugin: Posts 2 Posts] Again, have_posts() error’ 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/)

 * 3 replies
 * 2 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-again-have_posts-error/#post-2463632)
 * Status: not resolved