Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Get posts which are connected to several other posts (connected to x AND y)

  • Resolved harryrobbins

    (@harryrobbins)


    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/

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

    (@scribu)

    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.

    Thread Starter harryrobbins

    (@harryrobbins)

    Fantastic.

    Thanks for the super-quick response.

    All the best,

    Harry

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Posts 2 Posts] Get posts which are connected to several other posts (connected to x AND y)’ is closed to new replies.