-
Notifications
You must be signed in to change notification settings - Fork 261
Reciprocal connections
Only for version 0.9.6-alpha or newer.
An indeterminate connection type is one in which at least one post type appears both in the 'from' arg and in the 'to' arg:
p2p_register_connection_type( array(
'from' => 'post',
'to' => array( 'post', 'page' )
) );
Because 'post' appears twice, when editing a post in the administration area, P2P can't tell if you want to create a connection from the current post or to the current post. There are two ways to handle this:
p2p_register_connection_type( array(
'from' => 'employee',
'to' => 'employee',
'cardinality' => 'one-to-many',
'title' => array( 'from' => 'Managed by', 'to' => 'Manages' )
);
In this mode, when editing an employee, you will see two meta boxes, one titled 'Managed by' and another one titled 'Manages'.
Arguably, you could also do this by making the 'employee' post type hierarchical, but with P2P you can change your mind and set 'cardinality' => 'many-to-many'
easily.
p2p_register_connection_type( array(
'from' => 'person',
'to' => 'person',
'reciprocal' => true,
'title' => 'Friends with'
);
'reciprocal' => true
simply means that the direction is not important. All connections will show up in a single box.