Posts 2 Posts: Version 0.9

Admin Box Enhancements

admin box

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:

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. :)

comments powered by Disqus