scribu/wp-posts-to-posts — Issue #123: Custom rewrite and many-to-many relations
Author: Rayken
Created: 2012-02-25 13:07:01+00:00
State: open

## Custom rewrite and many-to-many relations
One CPT for products and another CPT for spare parts.

CPT 1: **products**
Permalink: example.com/products/**productName**

CPT 2: **spare_parts**
Permalink: example.com/spare-parts/**%productName%**

The desired end-result is if one would browse /spare-parts/**%productName%** it would display every spare part this specific product is related to, so basically one would be able to view _all_ spare parts for a specific product since many products can have many spare parts (many-to-many).

#### When creating a spare part one would relate this to a product

```PHP
'posts_to_posts',
'from' => 'spare_parts',
'to' => 'products',
'cardinality' => 'many_to_many' // Not sure here, what should be used?
) );
?>
```

#### Question is
How would one be able to pull all related posts made with "Posts 2 Posts" belonging to a specific post from CPT1 and being able to display them under CPT2?

So imagine if "**product1**" from _CPT1 (products)_ is related to "**part1, part2, part3**" from _CPT2 (spare_parts)_ - viewing these through /spare-parts/**product1** would show every spare part for **product1**.