Version 0.4

Using a taxonomy to store post-to-post connections was an interesting exercise. It worked, but when it came time to extend it, it felled flat on its face.

That’s why connections are now stored in a custom table, with an additional meta table for adding arbitrary information per connection.

It is now possible to connect the same two posts twice, but with different metadata, something that would be needed in Justin Tadlock’s movies scenario, for example.

The procedure for migrating old connections is the same as in the previous version: go to /wp-admin/?migrate_p2p and you’re done. (Make sure you have a recent database backup before you do this.)

When searching for posts to connect, it will search only by post title and not by content, as in previous versions.

Reciprocal connections are now stored only once.

Speaking of reciprocal connections, most function in the API accepted a the third parameter, which used to be $reciprocal = false. It has been replaced with $data = array(). More info can be found in the file api.php.

Unless you’re doing advanced stuff, you shouldn’t need to touch the API, though. You can just use WP_Query or get_posts():

Get posts connected from a particular post: $post_id -> $posts

$connected = get_posts( array(
  'suppress_filters' => false,
  'post_type' => 'book',
  'connected_from' => $post_id,
) );

Get posts connected to a particular post: $post_id <- $posts

$connected = get_posts( array(
  'suppress_filters' => false,
  'post_type' => 'book',
  'connected_to' => $post_id,
) );

Get connected posts, regardless of direction: $post_id <- $posts OR $post_id -> $posts

$connected = get_posts( array(
  'suppress_filters' => false,
  'post_type' => 'book',
  'connected' => $post_id,
) );

Version 0.3

There was an interesting discussion on wp-hackers about how best to store many-to-many relationships between posts.

The conclusion was that custom fields are probably the worst solution. While creating a custom table is the most straightforward way to do it, using a custom taxonomy has the most benefits. The most important one is that, when done right, no hand-written SQL is required.

So, this version of the plugin uses a hidden taxonomy to store the connections between posts.

If you were using an older version of the plugin, go to /wp-admin/?migrate_p2p to migrate your connections. You should probably make a database backup beforehand, just in case.

Besides that, the parameter order for p2p_get_connected() and p2p_list_connected() were changed. See all the API changes.

Version 0.2

You now have the ability to create multiple connections of the same type from the admin. This was the most requested feature and you should thank Patrik Bóna for providing the initial implementation.

the new metabox

The API functions have also changed (and are now documented), so you might want to take another look at them. I’ve also added a new helper function called p2p_list_connected().

Version 0.1

With custom post types coming to WordPress 3.0, a feature that’s needed on complex sites is the ability to create relationships between posts of different types.

For example, if you have a ‘review’ post type, you’ll probably want to be able to link it to an ‘event’ post type. Once you register this connection type, you will see a dropdown of events on the review editing screen. (The dropdown will likely be replaced with something more scalable in a future version.)

You can manage and retrieve connections using the provided API functions.

The plugin does not create any new database tables; the connections are stored in the postmeta table.

Version 0.1 is a developer preview release. It’s not meant for casual users.