Title: [Plugin: Posts 2 Posts] Returning the Connection Information Value
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Returning the Connection Information Value

 *  Resolved [argeee](https://wordpress.org/support/users/argeee/)
 * (@argeee)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/)
 * Hi Scribu,
    Now I’m trying to get the arbitrary value that I insert in the connection
   information array from outside the loop. I have looked at Twansparant question
   and looked at the github code but the answer escapes me. My code is for functions.
   php:
 *     ```
       $my_connection_type = p2p_register_connection_type( array(
       	'from' => 'product',
       	'to' => 'client',
   
       	'fields' => array(
       		'product_link' => 'link'
       		)
       	)
        );
       ```
   
 * and in the page:
 *     ```
       <?php
       $wp_query = new WP_Query(array(
           'post_type' => 'client',
           'client_type' => 'Distributor'));
   
       echo '<h2>' . _e('Where to buy', 'eq_power') . '</h2>';
       while ($wp_query->have_posts() ) : $wp_query->the_post();
        echo p2p_get_meta($post->p2p_id, 'product_link', true);
       endwhile;
   
       wp_reset_postdata();
       ?>
       ```
   
 * thanks
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/#post-2356549)
 * First of all, does the product link change depending on which client the product
   is connected to? If not, it should be a normal product custom field:
 * [http://codex.wordpress.org/Custom_Fields](http://codex.wordpress.org/Custom_Fields)
 *  Thread Starter [argeee](https://wordpress.org/support/users/argeee/)
 * (@argeee)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/#post-2356550)
 * Yes. The idea being that the link is a placeholder for our product at the distributor’s
   website. The first part of the link does not change, but the last part, the part
   associated with the product id does.
 * Thanks again
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/#post-2356551)
 * Ok, then p2p_get_meta() doesn’t work because your WP_Query isn’t connecting any
   products. It just gets a list of clients.
 * Assuming the code is run on `single-product.php`, try using:
 *     ```
       $wp_query = $my_connection_type->get_connected( get_queried_object_id(), array(
         'client_type' => 'Distributor'
       );
       ```
   
 * Otherwise, you’ll have to replace `get_queried_object_id()` with whatever product
   id you want to connect.
 *  Thread Starter [argeee](https://wordpress.org/support/users/argeee/)
 * (@argeee)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/#post-2356785)
 * Hi Scribu,
    I have finally have been able to come back to this. However, for 
   the life of me I can’t make it to work. The page is single-product, I the client
   type is a custom post with ‘distributor’ as taxonomy type.
 * I have turned debug on and I get:
    Notice: Undefined variable: my_connection_type
 * Even if I have in the function.php ‘global $my_connection_type’
 * Using version 1.0
 * thanks,
 * mauro
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/#post-2356786)
 * Try using a connection type id, as described here:
 * [https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage](https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage)
 *  Thread Starter [argeee](https://wordpress.org/support/users/argeee/)
 * (@argeee)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/#post-2356790)
 * Thanks, now it works. Here is the code:
 * In the functions.php I have included the id:
 *     ```
       function my_connection_types() {
       	// Make sure the Posts 2 Posts plugin is active.
       	if ( !function_exists( 'p2p_register_connection_type' ) )
   
       p2p_register_connection_type( array(
       		'id'=>'product_id_link',
       		'from' => 'product',
       		'to' => 'client',
       		'fields' => array(
       			'product_link' => 'link'
       			)
       		)
       	 );
       }
   
       add_action('init', 'my_connection_types', 100);
       ```
   
 * in the single-product.php page I have (in php tags):
 *     ```
       $wp_query = p2p_type( 'product_id_link' )->get_connected( get_queried_object_id(), array(
         'client_type' => 'Distributor'));
       echo '<h2>' . _e('Where to buy', 'eq_power') . '</h2>';
       while ($wp_query->have_posts() ) : $wp_query->the_post();
        echo p2p_get_meta($post->p2p_id, 'product_link', true);
       endwhile;
       wp_reset_postdata();
       ```
   
 * I hope this is of help for someone.
 * Mauro

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

The topic ‘[Plugin: Posts 2 Posts] Returning the Connection Information Value’ 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/)

 * 6 replies
 * 2 participants
 * Last reply from: [argeee](https://wordpress.org/support/users/argeee/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-returning-the-connection-information-value/#post-2356790)
 * Status: resolved