Title: [Plugin: Posts 2 Posts] Order main query using connected item title
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Order main query using connected item title

 *  [Tim Smith](https://wordpress.org/support/users/creativeinfusion/)
 * (@creativeinfusion)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-order-main-query-using-connected-item-title/)
 * I’d like to be able to sequence the results for a custom post type archive using
   the title from a connected custom post type.
 * For example, post types product and manufacturer with a one-to-many connection
   from manufacturer to product.
 * On the product archive, I’d like to be able to order them by manufacturer name
   then by product name.
 * I don’t want the overhead of doing a main WP Query, then chucking it away generating
   a new query for manufacturers and using each_connected on that.
 * What I wondered was whether use each_connected (there’s a couple of examples 
   in this support forum) in the WP_Query with some sort option, or by using the
   posts_order filter manually. I’d then use pre_get_posts to tweak the main query.
 * I’m failing at step one though, and can’t get each_connected to fire up from 
   a WP_Query, so doing
 *     ```
       $products_with_connection=new WP_Query(array(
       	'post_type'=>'product',
       	'nopaging'=>true,
       	'orderby'=>'name',
       	'order'=>'ASC',
       	'each_connected' => array(
       		'post_type' => 'manufacturer',
       		'nopaging' => true
       	)
       ));
       ```
   
 * makes no difference to the results with/without each connected.
 * Am I barking up the wrong tree here, and how would you achieve the objective?
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Thread Starter [Tim Smith](https://wordpress.org/support/users/creativeinfusion/)
 * (@creativeinfusion)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-order-main-query-using-connected-item-title/#post-3070967)
 * BTW this plugin is indispensable and a masterful piece of work.
 * Further to my problem and for reference that each_connected approach I’m trying
   use on WP_Query is taken from scribu’s answer on [http://wordpress.org/support/topic/plugin-posts-2-posts-how-to-call-two-post-types-connected-in-one-query](http://wordpress.org/support/topic/plugin-posts-2-posts-how-to-call-two-post-types-connected-in-one-query)
 * Any pointers gratefully received, even if it’s just a case of I’m doing it wrong
   and need to filter my own order by somehow, or (worst case redundant data method)
   set up a post meta as well and use tax queries to sort by it.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-order-main-query-using-connected-item-title/#post-3070975)
 * I’m afraid you’ll have to hook into the ‘posts_orderby’ filter yourself to achieve
   this.
 *  Thread Starter [Tim Smith](https://wordpress.org/support/users/creativeinfusion/)
 * (@creativeinfusion)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-order-main-query-using-connected-item-title/#post-3070979)
 * That’s fine, thanks for taking the time to answer. I did figure that your connection
   order by would take over (which incidentally works marvellously for the usual
   case of showing items related to ones on the page in question, just not for my
   use case here).
 * Is using each_connected on a WP_Query like that supported? If not I guess I’d
   need to figure out all the joins as well to even have access to the right columns
   for sorting.

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

The topic ‘[Plugin: Posts 2 Posts] Order main query using connected item title’ 
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/)

 * 3 replies
 * 2 participants
 * Last reply from: [Tim Smith](https://wordpress.org/support/users/creativeinfusion/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-order-main-query-using-connected-item-title/#post-3070979)
 * Status: not resolved