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.

Comments (14)

  • Jens says:

    Thanks, what would be use case for p2u or u2u connections?

    • scribu says:

      Oh, plenty. For example:

      • lists of favorite posts of a user
      • having a post reviewed by multiple editors before publication
      • private messages between users

      Note that for each connection, you can also store the date at which it was created, as well as any other arbitrary information.

  • Jens says:

    Sounds great.

  • geminorum says:

    great, thanks.

  • Toine Kamps says:

    Hi scribu,
    After updating to 1.1.1 I get this error: ‘Call to undefined function p2p_split_posts()’
    Any idea how to fix this?

    • scribu says:

      I decided not to include the p2p_split_posts() function in the plugin anymore, since you seem to be the only one that needs it.

      Here is the function definition:

      /**
       * Split some posts based on a certain connection field.
       *
       * @param object|array A WP_Query instance, or a list of post objects
       * @param string $key p2pmeta key
       */
      function p2p_split_posts( $posts, $key ) {
      	if ( is_object( $posts ) )
      		$posts = $posts->posts;
       
      	$buckets = array();
       
      	foreach ( $posts as $post ) {
      		$value = p2p_get_meta( $post->p2p_id, $key, true );
      		$buckets[ $value ][] = $post;
      	}
       
      	return $buckets;
      }

      Just put it in your functions.php file.

  • A. says:

    “..supporting connections between posts on different blogs in a multisite network..”
    The answer to the multilingual issue, please and thanks!!

    • scribu says:

      That’s interesting. Note that the kind of support I’m thinking about is one in which a connection type connects at most two different blogs, i.e. posts from blog A are connected to posts from blog B.

      So, if you are going for a different language per blog, you would need a new connection type for each additional language.

      • A. says:

        Fair enough.. I don’t mind having a box for each language..
        I’m currently using (in a very small 20 pages site with 2 languages):
        `’reciprocal’ => true,
        ‘cardinality’ => ‘many-to-one’`
        to emulate a “one-to-one” connection.

        But anyhow, this is great news, I’m starting a project now in which hopefully this new feature will be put to the test (coding would start sometime in January probably).
        Thanks again!

  • Modesty says:

    Scribu,

    after the update there is no option to add new posts in the connection box. Is there something we need to do to enable this?

  • Modesty says:

    $my_connection_type = p2p_register_connection_type( array(
    ‘from’ => ‘post’,
    ‘to’ => ‘osobe’,
    ‘fields’ => array(
    ‘uloga’ => ‘uloga:’,
    ‘lik’ => ‘lik:’
    ),
    ‘reciprocal’ => true,
    ‘prevent_duplicates’ => false,

    ));

    $my_connection_type = p2p_register_connection_type( array(
    ‘from’ => ‘osobe’,
    ‘to’ => ‘filmovi’,
    ‘fields’ => array(
    ‘uloga’ => ‘uloga:’,
    ‘lik’ => ‘lik:’
    ),
    ‘reciprocal’ => true,
    ‘prevent_duplicates’ => false,
    ));