Title: [Plugin: Posts 2 Posts] Ordering BY connected posts
Last modified: August 19, 2016

---

# [Plugin: Posts 2 Posts] Ordering BY connected posts

 *  [JsonB123](https://wordpress.org/support/users/jsonb123/)
 * (@jsonb123)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-ordering-by-connected-posts/)
 * What I’m doing:
    A search results page. Currently it grabs a bunch of posts two
   different ways, both using the connected_to argument for query_posts. Here’s 
   an example: Search 1:
 *     ```
       $args = array(
       'post_type' => 'my-type',
       'connected_to' => $_GET['some-other-type_ID']
       );
       ```
   
 * and my other search
 *     ```
       $args = array(
       'post_type' => 'my-type',
       'connected_to' => $_GET['some-other-OTHER-type_ID']
       ```
   
 * This works great at getting the posts that are connected…however I need them 
   to be ordered by the connected post’s ID. So I tried using the p2p_to parameter
   as a meta_key and orderby meta_value_num but then soon realized that p2p_to is
   not a meta value. I’m not seeing any other way to do this other than getting 
   the posts and THEN doing a custom sort myself using the p2p_id and then printing
   them.
 * My other concern is that on the second search I’m doing, I still want to sort
   by ‘some-other-type’ even though I’m getting the connected_to from ‘some-other-
   OTHER-type’. The posts I’m printing out are connected to both types always, so
   the connection always exists for sorting on, even though I didn’t use it for ‘
   connected_to’.
 * Wow, this sounds complex!
 * Is there an easier way to do this by using the Posts 2 Posts api that I’m not
   seeing? Thanks for any help.
 * [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)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-ordering-by-connected-posts/#post-2040564)
 * So, to clarify, you want to sort the posts on the front-end based on the order
   of the connections that you see in the admin area.
 * No, there is no easy way of doing this currently.
 * Also, we first need a way to order the connections themselves:
 * [http://wordpress.org/support/topic/plugin-posts-2-posts-ordering-connected-posts](http://wordpress.org/support/topic/plugin-posts-2-posts-ordering-connected-posts)
 * If I didn’t get it, please provide an example.
 *  Thread Starter [JsonB123](https://wordpress.org/support/users/jsonb123/)
 * (@jsonb123)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-ordering-by-connected-posts/#post-2040577)
 * Hi Scribu,
 * Yes, that is exactly what I’m talking about. I just want to group the posts together
   based on other connections, e.g.:
 * Color (connected) Food
    Red => Apple Red => Strawberry Green => Avacado Yellow
   => Banana Green => Pickle
 * So that when I print them it would print:
    – Banana – Avacado – PIckle – Apple–
   Strawberry
 * I just need them grouped. I’ll have to just do more than one loop, create a new
   array or stdClass object and add the extra data to it, probably just the connection’s
   post id, so that I can sort on that.
 * Another fix would be to somehow add a new metakey/value pair to anything getting
   connected on each post (not sure exactly what the best value would be here…perhaps
   just the post title of the thing(s) that the current post is connected to?), 
   so that you could use meta_query on it..though I guess that might be messy from
   the plugin’s standpoint?
 * Thanks for trying to help 🙂

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

The topic ‘[Plugin: Posts 2 Posts] Ordering BY connected posts’ 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: [JsonB123](https://wordpress.org/support/users/jsonb123/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/plugin-posts-2-posts-ordering-by-connected-posts/#post-2040577)
 * Status: not resolved