• Tim Smith

    (@creativeinfusion)


    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/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Tim Smith

    (@creativeinfusion)

    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

    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

    (@scribu)

    I’m afraid you’ll have to hook into the ‘posts_orderby’ filter yourself to achieve this.

    Thread Starter Tim Smith

    (@creativeinfusion)

    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.