WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Get posts which are connected to several other posts (connected to x AND y) (3 posts)

  1. harryrobbins
    Member
    Posted 1 year ago #

    Hi Scribu,

    thanks for all your fantastic work - it's massively improved WordPress.

    Is it possible to find posts that are linked to several different posts.

    For example, if I had Books connected to Countries (in which they are available) and Authors, is there any way to query for all Books which are connected to a particular Country AND to a particular Author?

    Thanks in advance for your help,

    Harry

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

  2. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    It's possible with two queries:

    $connected_to_country = get_posts( array(
      'connected_type' => 'books_to_countries',
      'connected_items' => $country_id,
      'nopaging' => true,
      'fields' => 'ids',
      'suppress_filters' => false,
    ) );
    
    $connected_to_country_and_author = get_posts( array(
      'connected_type' => 'books_to_authors',
      'connected_items' => $author_id,
      'nopaging' => true,
      'post__in' => $connected_to_country,
      'suppress_filters' => false,
    ) );

    Obviously, you need to pass your own connection type names and post ids.

  3. harryrobbins
    Member
    Posted 1 year ago #

    Fantastic.

    Thanks for the super-quick response.

    All the best,

    Harry

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic