Skip to content

Checking specific connections

scribu edited this page Aug 7, 2012 · 4 revisions

Sometimes, you need to check if two specific posts (or users) are connected. Here's how you can do that:

<?php
$p2p_id = p2p_type( 'YOUR_CONNECTION_TYPE' )->get_p2p_id( $post_a, $post_b );

if ( $p2p_id ) {
  // connection exists
  var_dump( p2p_get_meta( $p2p_id, 'some_key', true ) );
} else {
  // connection doesn't exist
}
Clone this wiki locally