The Stiz Media, LLC

Making your website work for you

  • Styles for Genesis
    • FAQs
  • Cart
  • My Account
  • Home
  • Web Design
  • Portfolio
  • Resources
  • Blog
  • Contact
  • Follow me

Powerful websites, with style.

You are here: Home / Tutorials / Create Posts 2 Posts ‘connections’ with the WordPress Rest API

Create Posts 2 Posts ‘connections’ with the WordPress Rest API

August 28, 2016 JiveDig 6 Comments

Restful P2P Example

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!).

Restful P2P example

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?

Related Posts

  • CPT filter by taxonomy
    Custom Post Type Filter Admin By Custom Taxonomy
  • Remove Items from TinyMCE editor
    Remove Buttons/Items From The WordPress TinyMCE Editor
  • EA Share Count SMS button
    Add SMS share button to EA Share Count plugin

Tutorials Posts 2 Posts

‹ Add SMS share button to EA Share Count plugin

About JiveDig

Howdy, I'm Mike Hemberger. I like to build nice websites and web apps with WordPress and Genesis Framework.

Feel free to email, and you'll be speaking directly with me.

Try The Most Powerful Genesis Child Theme Ever Created

Mai Theme is the most customizable Genesis child theme (and plugin!) available. Check it out now!

Learn More @ MaiTheme.com

Our posts, directly to your inbox

Comments

  1. Luke Cavanagh says

    August 29, 2016 at 12:15 pm

    Thanks for sharing!

    Reply
    • JiveDig says

      August 29, 2016 at 12:28 pm

      Thanks for checking it out!

      Reply
  2. Kevin says

    November 29, 2016 at 11:31 am

    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

    Reply
    • JiveDig says

      January 9, 2017 at 9:48 am

      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!

      Reply
  3. Sam Cohen says

    May 19, 2017 at 1:16 pm

    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!

    Reply
    • JiveDig says

      July 10, 2017 at 10:48 am

      Agreed. That was the goal of this plugin, to make it really easy to create Favorites, Saved, Bookmarked, etc posts/CTP’s.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Our posts, directly to your inbox


Howdy, I'm Mike Hemberger. I like to build nice websites and web apps with WordPress and Genesis Framework.

I'm passionate about everything I do, and it resonates in all of my work.

Feel free to email, and you'll be speaking directly with me.

Recent Posts

Restful P2P Example

Create Posts 2 Posts ‘connections’ with the WordPress Rest API

EA Share Count SMS button

Add SMS share button to EA Share Count plugin

ACF Extras

ACF Extras officially launched! A community of code snippets and field groups

Remove Items from TinyMCE editor

Remove Buttons/Items From The WordPress TinyMCE Editor

  • My Account
  • Affiliate Area
  • Log In
  • GitHub
  • Google+
  • Instagram
  • Twitter
  • YouTube
The Stiz Media, LLC, 12 Russling Rd., Hackettstown 07840

Copyright © 2019 · The Stiz Media, LLC · All Rights Reserved