[Plugin: Posts 2 Posts] How does it work?

I recently discovered Scribu’s Posts 2 Posts plugin, which seems to be exactly what I was looking for in order to connect pages and posts for a big editorial website.

But I cannot get it to work, which is frustrating because the principle seems really easy. I followed the wiki basic usage example, in my functions.php I have :

function my_connection_types() {
if ( !function_exists( 'p2p_register_connection_type' ) )
    return;

p2p_register_connection_type( array( 
    'from' => 'post',
    'to' => 'page'
) );
}
add_action( 'init', 'my_connection_types', 100 );

And in page.php :

$connected = new WP_Query( array(
    'post_type' => 'post',
    '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();

I have a post called “Tacos”, which I connected to the page called “About”.

When I go to the “About” page, I see “Related posts:”, but nothing else after that (ie. where is my Taco ?)

a print_r( $connected ) gives the following :

WP_Query Object ( [query_vars] => Array ( [post_type] => post [connected_from] => 2 [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [meta_query] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [posts_per_page] => 10 [nopaging] => [comments_per_page] => 50 [no_found_rows] => [order] => DESC [orderby] => il_posts.post_date DESC ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( ) [relation] => AND ) [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => 1 [is_404] => [is_comments_popup] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash] => 90a220b2f180d3ea6ccbd9473e26ec4c [query_vars_changed] => [query] => Array ( [post_type] => post [connected_from] => 2 ) [request] => SELECT SQL_CALC_FOUND_ROWS il_posts.*, il_p2p.* FROM il_posts INNER JOIN il_p2p WHERE 1=1 AND il_posts.post_type="post" AND (il_posts.post_status="publish" OR il_posts.post_status="private") AND il_posts.ID = il_p2p.p2p_to AND il_p2p.p2p_from IN (2) ORDER BY il_posts.post_date DESC LIMIT 0, 10 [posts] => Array ( ) )

What am I missing?

ps. WordPress 3.1.1, Posts 2 Posts 0.7 and PHP 5.3.3

1 Answer
1

try 'connected' => get_queried_object_id() instead of 'connected_from' => get_queried_object_id()

Leave a Comment