WordPress.org

Support

Support » Plugins and Hacks » Posts 2 Posts » [Plugin: Posts 2 Posts] Get posts from/to more than one other post

[Plugin: Posts 2 Posts] Get posts from/to more than one other post

  • Hi,

    I have question (probably suggestion) about one feature.

    fe.
    array(‘post_type’ => ‘example_type, ‘connected_from’ => array(id1, id2, …),);

    We will get all posts connected from ID1, ID2 and so on. But how we can get posts with ‘operator’ AND ? That theyre are connected to all this ID’s in the same time.

    fe. Photos from Event added by User (all Custom post types).

    Regards,
    Piotr Ryczek

    http://wordpress.org/extend/plugins/posts-to-posts/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author scribu

    @scribu

    This is not supported currently, but it is possible with some funky SQL.

    Photos from Event added by User (all Custom post types).

    I’m not sure I understand this example.

    Registered connections:
    User -> Photo
    Event -> Photo

    And we wanna get photos from User and Event in the same time.

    Plugin Author scribu

    @scribu

    Oh, so User is a custom post type. I see.

    Plugin Author scribu

    @scribu

    This has been fixed since P2P 1.2 I think:

    $query = new WP_Query( array(
      'connected_type' => 'YOUR_CONNECTION_TYPE',
      'connected_items' => array( $post1, $post2, ... )
    ) );

    It works with both post IDs and full post objects.

    Yes, but the SQL query generated by that code uses:
    wp_posts.ID = wp_p2p.p2p_from AND wp_p2p.p2p_to IN (412,416,414)

    Is there a way to make it exclusive?

    Scenario: I have two CPTs. Recipes and Ingredients. I want to generate a query to get all the Recipes that has all those ingredients, not any of them.

    Plugin Author scribu

    @scribu

    Oh, sorry, I didn’t read through the original topic.

    No, querying for posts connected both to post 1 AND to post 2 is still not supported.

    So, SQL it is 🙂

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Posts 2 Posts] Get posts from/to more than one other post’ is closed to new replies.
Skip to toolbar