WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
Get posts from/to more than one other post (9 posts)

  1. Nero12
    Member
    Posted 2 years ago #

    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/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. Nero12
    Member
    Posted 2 years ago #

    Registered connections:
    User -> Photo
    Event -> Photo

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

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

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

  5. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  6. Daniel Dvorkin (MZAWeb)
    Member
    Posted 1 year ago #

    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.

  7. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  8. Daniel Dvorkin (MZAWeb)
    Member
    Posted 1 year ago #

    So, SQL it is :)

    Thanks!

  9. Daniel Dvorkin (MZAWeb)
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic