Admin Box Enhancements
In the above screenshot you can see the following new features:
Multiple Connections Per Post Type
Besides the ‘fields’ parameter, there’s also a ‘data’ parameter. This can be used to distinguish between connection types:
p2p_register_connection_type( array(
'from' => 'actor',
'to' => 'actor',
'reciprocal' => true,
'title' => array( 'from' => 'Doubles', 'to' => 'Main Actor' ),
'data' => array( 'type' => 'doubles' ),
) );
p2p_register_connection_type( array(
'from' => 'actor',
'to' => 'actor',
'reciprocal' => true,
'title' => 'Friends with',
'data' => array( 'type' => 'friends' )
) );
API Overhaul
Should I use ‘connected_to’ or ‘connected_from’? Erm… I’ll just use ‘connected’.
Even I was tired of having to think about it. No more.
In previous versions, connection types were tightly coupled with the admin box code. I extracted all the logic into a P2P_Connection_Type
class, which should make querying for posts a lot easier.
The old way of doing things still works, except in the following cases:
p2p_register_connection_type()
returns aP2P_Connection_Type
instance now. Therefore,'from' => array( ... )
and'to' => array( ... )
are not accepted anymore.p2p_each_connected()
functions and'each_connected'
query vars are gone. UseP2P_Connection_Type->each_connected()
instead:
Old:
$my_query = new WP_Query( array(
'ignore_sticky_posts' => true,
'post_type' => 'artist',
'each_connected' => array(
'post_type' => 'art',
)
) );
New:
$my_query = new WP_Query( array(
'ignore_sticky_posts' => true,
'post_type' => 'artist',
) );
$my_connection_type->each_connected( $my_query );
All the tutorials on the wiki have been updated to use the hot new API, so feel free to dig in. :)