web-dev-qa-db-fra.com

[Plugin: Posts 2 Posts] Comment ça marche?

J'ai récemment découvert le plugin Posts 2 Posts de Scribu , qui semble correspondre exactement à ce que je cherchais pour connecter des pages et des publications sur un grand site éditorial.

Mais je ne peux pas le faire fonctionner, ce qui est frustrant parce que le principe semble vraiment facile. J'ai suivi l'exemple d'utilisation de base du wiki , dans mon functions.php:

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 );

Et dans 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();

J'ai un article appelé "Tacos", que j'ai connecté à la page "A propos de".

Quand je vais à la page "À propos de", je vois "Articles connexes:", mais rien d’autre après (c’est-à-dire où est mon Taco?)

un print_r( $connected ) donne les informations suivantes:

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 ( ) )

Qu'est-ce que je rate?

ps. Wordpress 3.1.1, Publications 2 Publications 0.7 et PHP 5.3.3

2
mike23

essayez 'connected' => get_queried_object_id() au lieu de 'connected_from' => get_queried_object_id()

2
Milo