-
Notifications
You must be signed in to change notification settings - Fork 263
Checking specific connections
scribu edited this page Aug 8, 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
$connection_field = p2p_get_meta( $p2p_id, 'YOUR_FIELD_KEY', true );
var_dump( $connection_field );
} else {
// connection doesn't exist
}
$post_a
and $post_b
are post (or user) objects.