私は最近Scribuの Posts 2 Posts プラグインを発見しました。これはまさに私が大きな社説のウェブサイトのためにページと記事をつなぐために探していたもののようです。
しかし、私はそれを機能させることができません、それは原理が本当に簡単に思えるのでイライラしています。私は ウィキの基本的な使用例 に従いました。
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 );
そして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();
私は "About"というページに接続した "Tacos"という投稿を持っています。
"About"ページに行くと、 "Related posts:"と表示されますが、それ以外に何もありません(つまり、私のTacoはどこにありますか?)
print_r( $connected )
は次のようになります。
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 ( ) )
何が足りないの?
ps。 Wordpress 3.1.1、投稿2投稿0.7およびPHP 5.3.3
'connected' => get_queried_object_id()
の代わりに'connected_from' => get_queried_object_id()
を試してください