-
Notifications
You must be signed in to change notification settings - Fork 261
Reciprocal connections
scribu edited this page Jul 11, 2011
·
21 revisions
When registering a connection type, you can set the 'reciprocal' flag:
p2p_register_connection_type( array(
'from' => 'post',
'to' => 'page',
'reciprocal' => true
) );
Now you will see the connection box whenever you edit a post or a page and you can create a connection from either place and it will show up in both.
Important: Connections are created in a single direction, from post → page.
Say you want to connect posts to other posts:
p2p_register_connection_type( array(
'from' => 'post',
'to' => 'post',
'reciprocal' => true
) );
And then you want to display all the connections related to a certain post. Instead of using 'connected_to' or 'connected_from', you can use the 'connected' query var:
$connected = new WP_Query( array(
'post_type' => 'post',
'connected' => get_queried_object_id()
) );
This will return current_post
→ other_post
connections, as well as other_post
→ current_post
.