Title: [Plugin: Posts 2 Posts] Advanced each_connected()
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Advanced each_connected()

 *  Resolved [Derek Perkins](https://wordpress.org/support/users/ploobers/)
 * (@ploobers)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-advanced-each_connected/)
 * I’ve got a question on how to do some filtering and sorting on the each_connected()
   function. I’ve got a lot of connections in my database, but I don’t always necessarily
   need all of the information. For example, I may have a product (cpt) linked to
   20 stores (cpt) with pricing information stored as p2p_meta. Sometimes I’ll show
   all the pricing, but sometimes in a smaller widget area, all I want to show is
   the lowest three prices. Here is kind of how I see it working.
 *     ```
       $query = new WP_Query( 'post_type'=>'product', 'posts_per_page'=>'5' );
       p2p_type( 'product_store' )->each_connected( $query, array( 'orderby'=>'p2p_meta_price', 'order'=>'ASC', 'posts_per_page'=>'3' );
       ```
   
 * I haven’t dug into the p2p queries to see how simple this would be to implement,
   but it would be nice. If that doesn’t work, I’d use each_connected as it is now
   and just do my sorting and filtering on the returned array itself.
 * [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)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-advanced-each_connected/#post-2554838)
 * `each_connected()` already accepts additional query vars as the second parameter.
 * However, it’s not possible to limit the number of connected items per post. You’ll
   have to do that yourself in PHP.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Posts 2 Posts] Advanced each_connected()’ 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/)

 * 1 reply
 * 2 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-advanced-each_connected/#post-2554838)
 * Status: resolved