Title: [Plugin: Posts 2 Posts] Using p2p_get_meta in widget sidebar
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Using p2p_get_meta in widget sidebar

 *  [John](https://wordpress.org/support/users/jsing/)
 * (@jsing)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p_get_meta-in-widget-sidebar/)
 * I am trying to list data using the Executable PHP Widget by Otto to display php
   in a sidebar. The code works fine in a page template but only returns the post
   title in the sidebar. I don’t know if this has something to do with the PHP Widget
   plugin or P2P. Anyone have a suggestion on how to get it to work? Here is the
   code I am using:
 *     ```
       <h2>Customer Relationship</h2>
       <?php
       // Find connected customers
       $connected = new WP_Query( array(
         'connected_type' => 'posts_to_customers',
         'connected_items' => get_queried_object(),
         'nopaging' => true,
         'connected_meta' => array(
       	array(
                 'key' => 'customertype',
       		'value' => $customertype,
                  )
               )
   
       ) );
   
       // Display connected customers
       if ( $connected->have_posts() ) :
       ?>
       <ol>
       <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
       	<li><a href="<?php the_permalink(); ?>"> <?php the_title();?> </a>
       </li>
       <?php
       $answer = p2p_get_meta($post->p2p_id, 'customertype', true);
       echo $answer;
       ?>
       <br/> 
   
       <?php endwhile; ?>
       </ol>
   
       <?php
       // Prevent weirdness
       wp_reset_postdata();
   
       endif;
       ?>
       ```
   
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p_get_meta-in-widget-sidebar/#post-2953140)
 * My guess is that you have to add `global $post` at the top of that code, but 
   I could be wrong.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Posts 2 Posts] Using p2p_get_meta in widget sidebar’ 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/)

## Tags

 * [Executable PHP Widget](https://wordpress.org/support/topic-tag/executable-php-widget/)

 * 1 reply
 * 2 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p_get_meta-in-widget-sidebar/#post-2953140)
 * Status: not resolved