• Resolved mike235

    (@mike235)


    Hi,

    Thanks for another great plugin, the possibilities of P2P are great. But I’m having some trouble making it work.

    I did the following, on a blank WP (3.1.1) and P2P (0.7), my PHP version is 5.3.3 :

    Created a custom post type named : publications

    Then in functions.php :

    function my_connection_types() {
    	if ( !function_exists( 'p2p_register_connection_type' ) )
    		return;
    
    	p2p_register_connection_type( array(
    		'from' => 'publications',
    		'to' => 'page'
    	) );
    }
    add_action( 'init', 'my_connection_types', 100 );

    and in page.php :

    $connected = new WP_Query( array(
    	'post_type' => 'publications',
    	'connected_from' => get_queried_object_id()
    ) );
    
    echo '<p>Related posts:</p>';
    echo '<ul>';
    	while( $connected->have_posts() ) : $connected->the_post();
    		echo '<li>';
    		the_title();
    		echo '</li>';
    	endwhile;
    echo '</ul>';
    
    wp_reset_postdata();

    This is exactly the examples from the wiki, I just adapted it to a custom post type. But it doesn’t work, all it shows is : “Related posts:”

    Am I missing something ?

Viewing 1 replies (of 1 total)
  • Thread Starter mike235

    (@mike235)

    Ok I got the answer here.

    It turns out you need to write :

    connected' => get_queried_object_id()

    instead of :

    connected_from' => get_queried_object_id()

    Now I’m very excited to play with P2P, as Scribu says the possibilities are endless !

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Posts 2 Posts] Can't get example to work’ is closed to new replies.