Title: [Plugin: Posts 2 Posts] Widget displays connected users, but &#039;basic usage&#039; code does not.
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Widget displays connected users, but 'basic usage' code does not.

 *  Resolved [poisoned.eden](https://wordpress.org/support/users/poisonededen/)
 * (@poisonededen)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-widget-displays-connected-users-but-basic-usage-code-does-not/)
 * I am incredibly confused – The ‘basic usage’ code doesn’t work when I try to 
   put it in a sidebar area.
 * I need it to work through the code in the template rather than through a widget,
   as I need to be able to
    1. limit it to display only one user when there are 
   multiple connected, and, 2. if there is no connected user, to display the user
   connected to the posts parent.
 * PLEASE tell me what I’m doing wrong! This is in my sidebar.php template file.
   It doesn’t seem to find any connected users.
 *     ```
       $connected = new WP_Query( array(
         'connected_type' => 'key_service_contact',
         'connected_items' => get_queried_object(),
         'nopaging' => true,
       ) );
   
       // Display connected pages
       if ( $connected->have_posts() ) :
       ?>
       <h3>Key Contact</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;
       ```
   
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-widget-displays-connected-users-but-basic-usage-code-does-not/#post-3001167)
 * The problem is that you’re using `WP_Query`, which will only return posts.
 * To get a list of users, use `get_users()`.
 *  Thread Starter [poisoned.eden](https://wordpress.org/support/users/poisonededen/)
 * (@poisonededen)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-widget-displays-connected-users-but-basic-usage-code-does-not/#post-3001337)
 * I knew it must be something simple…. Thank you very much!

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

The topic ‘[Plugin: Posts 2 Posts] Widget displays connected users, but 'basic usage'
code does not.’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [poisoned.eden](https://wordpress.org/support/users/poisonededen/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-widget-displays-connected-users-but-basic-usage-code-does-not/#post-3001337)
 * Status: resolved