There were some improvements commited to the development version of the plugin for a while and I thought I’d do a quick release, to get them in the hands of users.
With version 1.6, P2P development will effectively be entering hibernation mode. I won’t be working on any new features or bug fixes, since the plugin already works well enough on the single site where I use it. Also, I won’t be answering support questions anymore; sorry.
Of course, I’d be happy to review and merge pull requests that people open and still hope that I’ll eventually be able to hand it off to someone else.
When you need to create connections, there’s now a link that reveals the connection candidates. This saves vertical space when you’re doing something else in the post editing screen.
When you found the item you want to connect to, you can now click anywhere in the row, instead of just on the ‘+’ icon. This makes it both easier to target and less confusing. After the connection is created, you can click on the connected post’s title to edit it, as before.
Revamped connection querying
The SQL generated for querying connections is now more precise, so that trashed and auto-draft posts are ignored by default.
Also, you can now filter both ends of the connection. For example, you can find all pages connected to any posts in the ‘Tutorials’ category:
In this release, I focused on making the API more uniform; everything works for both posts-to-posts and posts-to-users connections now. This is possible because you can pass whole post and user objects, instead of just IDs.
I’m pleased to announce that the Posts 2 Posts plugin now also supports posts-to-users connections. (It supports users-to-users connections as well, but there’s no UI for them).
This is made possible by a new p2p_type column on the wp_p2p table, with which we can clearly distinguish between user ids and post ids. If you’re upgrading from a previous version of Posts 2 Posts, all the existing connections will be automatically updated to have the correct value for this column.
For the next version, I’m thinking of supporting connections between posts on different blogs in a multisite network.
With the WP 3.2 admin refresh, the connection box UI also received an overhaul:
A significant enhancement in this version is the ability to create draft posts from the connection box. The idea is to be able to make the connections first and then write the content. Hat tip to Oren Kolker.
Additionally, when a post is not published, you will see it’s status. Props Michael Fields for the suggestion.
p2p_each_connected() has been revamped to, hopefully, make it easier to use. There’s a detailed tutorial on the wiki:
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
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.
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.