[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?
- The topic ‘[Plugin: Posts 2 Posts] Order main query using connected item title’ is closed to new replies.