Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Advanced each_connected()

  • Resolved Derek Perkins


    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.

Viewing 1 replies (of 1 total)
  • Plugin Author scribu


    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.