Posts 2 Posts
[resolved] Advanced each_connected() (2 posts)

  1. Derek Perkins
    Posted 4 years ago #

    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.


  2. scribu
    Plugin Author

    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic