I’ve written a lightweight plugin to make it extremely easy to create Posts 2 Posts connections via the WordPress WP-API (Rest API). If you don’t know about Posts 2 Posts, it’s an extremely powerful (developer) plugin that allows you to create a ‘connection’ between 2 objects, often posts, pages, or CPT, but also users.
A typical example Posts 2 Posts (P2P) usage is a website where you have 2 custom post types, actors and movies. They exist as separate post types so they can easily be managed via the WP backend, and each post type can conveniently have its own set of custom fields associated with it. P2P allows you to ‘connect’ (one-to-many or many-to-many) an actor to the movies they were in, or vice-a-versa (optional).
Lately I’ve been using P2P for more user based connections like allowing a logged in user to ‘like’ or ‘favorite’ posts, mark a CPT as ‘completed’, or save posts/CPT’s to ‘wish lists’. When I think about the use cases for allowing connections between logged in users and a CPT, the ideas start flowing.
Using the WordPress Rest API allows the power and flexibility of P2P connections with the ease of the WP-API for creating the connections (front end, ajax = no page reload, woot!).
The Restful P2P plugin comes with a simple helper function to help you create/display a connection button.
That’s it. Everything else is handled for you. Nice and tidy.
Now is your turn. Give the Restful P2P plugin a try.
What are some use cases you have for a plugin like Restful P2P and Posts 2 Posts?
Thanks for sharing!
Thanks for checking it out!
Thanks for sharing JiveDig. Your plugin has already come is very useful on a project that I’m working on right now. This is my first foray into the WP REST API and it’s a steep learning curve but I’ve made some modifications to your code in order to use p2p as a one-directional ‘friend’ system where some users can send requests to other users who are in turn invited to ‘approve’ or decline’. I’ve done this by introducing a new variable of ‘request’ with arguments connect (default), request, accept, decline which attribute some meta to the connection.
My question is how might I extend your class to include a p2p_update_meta function that works in the same way as the connect and disconnect functions but only updates the meta? The update meta documentation on the p2p site is pretty light.
PS: You mention at the foot of the repo that you might remove the option to disconnect as you don’t see a use case for it. Well, I’m also using your plugin to allow users to register (and unregister) for events so it’s certainly useful in this case.
Thanks again
Kevin
Hey Kevin, we touched base already but just replying here for anyone that is interested. It would be cool to add p2p meta support to this plugin. I haven’t needed it yet, but it shouldn’t be too difficult to add another parameter.
As per removing the option to disconnect, I mean to make it optional. Then we can create connection buttons that are only for connecting or both connecting and disconnecting.
Thanks for checking it out!
This is really good to know!
P2P can actually make your posts:
favorited,
saved
checklisted
It would nice to have a write-up tut on these!
Agreed. That was the goal of this plugin, to make it really easy to create Favorites, Saved, Bookmarked, etc posts/CTP’s.