Title: Posts 2 Posts
Last modified: August 31, 2016

---

# Posts 2 Posts

 *  [shapuleto](https://wordpress.org/support/users/shapuleto/)
 * (@shapuleto)
 * [10 years ago](https://wordpress.org/support/topic/posts-2-posts-1/)
 * Hello everybody
 * I am using this plugin version 1.6.5 and is not working or half working… let 
   me set the context:
    My child’s theme function.php I have this code:
 *     ```
       function connection_posts_2_pages() {
       	p2p_register_connection_type( array(
       		'name'	=> 'posts_to_pages',
       		'from'	=> 'post',
       		'to'	=> 'page'
       	));
       }
       ```
   
 * My registered post types are:
 *     ```
       Array
       (
           [post] => post
           [page] => page
           [attachment] => attachment
           [revision] => revision
           [nav_menu_item] => nav_menu_item
           [acf] => acf
           [movie] => movie
           [actor] => actor
       )
       ```
   
 * When I go to my post related to a page I do have the page related to it, this
   is the code on single.php:
 *     ```
       $connected = new WP_Query( array(
       				  'connected_type' => "posts_to_pages",
       				  'connected_items' => get_queried_object(),
       				  'connected_direction' => 'from',
       				  'nopaging' => true,
       				) );
       				// Display connected pages
       				if ( $connected->have_posts()) :
       				?>
       				<h3>Related <?php echo "Pages"; ?>:</h3>
   
       <ul>
       				<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
   
       <li><a>"><?php the_title(); ?></a></li>
       				<?php endwhile; ?>
       				</ul>
       				<?php
       				// Prevent weirdness
       				wp_reset_postdata();
   
       				else: echo "no related Pages!";
       				endif;
       ```
   
 * But when I go to that page related to that post I have this error “Fatal error:
   Call to a member function have_posts() on a non-object”, the code on page.php
   is this:
 *     ```
       // Find connected posts
       				$connected = get_posts(
       					array(
       					  'connected_type' => 'posts_to_pages',
       					  'connected_items' => get_queried_object(),
       					  'nopaging' => true,
       					  'suppress_filters' => false
       					)
       				);
       				// Display connected pages
       				if ( $connected->have_posts()) :
       				?>
       				<h3>Related Pages:</h3>
   
       <ul>
       				<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
   
       <li><a>"><?php the_title(); ?></a></li>
       				<?php endwhile; ?>
       				</ul>
       				<?php
       				// Prevent weirdness
       				wp_reset_postdata();
   
       				else: echo "no related Pages!";
       				endif;
       ```
   
 * Normally if it is the same code and the connection is working in one direction,
   should work in the other direction right?
 * Any ideas guys
 * Thanks all

The topic ‘Posts 2 Posts’ is closed to new replies.

## Tags

 * [connection](https://wordpress.org/support/topic-tag/connection/)
 * [direction](https://wordpress.org/support/topic-tag/direction/)
 * [post to pages](https://wordpress.org/support/topic-tag/post-to-pages/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [shapuleto](https://wordpress.org/support/users/shapuleto/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/posts-2-posts-1/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
