プラグイン「Posts 2 Posts」がうまく機能しない
-
いつもありがとうございます
カスタム投稿Aとカスタム投稿Bという2つの異なるカスタムメニューを関連付けさせたいと思っています。
そこで今回プラグイン「Posts 2 Posts」を使用したいと思っています。
WordPress 6.0.2ですfunction.phpに
function my_connection_types() { p2p_register_connection_type( array( 'name' => 'posts_to_pages', 'from' => 'post', 'to' => 'page' ) ); } add_action( 'p2p_init', 'my_connection_types' );
page.phpに
<?php // Find connected pages $connected = new WP_Query( array( 'connected_type' => 'posts_to_pages', 'connected_items' => get_queried_object(), 'nopaging' => true, ) ); // Display connected pages if ( $connected->have_posts() ) : ?> <h3>Related pages:</h3> <ul> <?php while ( $connected->have_posts() ) : $connected->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php // Prevent weirdness wp_reset_postdata(); endif; ?>
としています。
カスタム投稿はそれぞれ Connected ****というところで関連づけを確認しています。
使い方について下記参考サイトにあるような情報を得て、いろいろためしてはみたのですが、投稿自体を取得できていないようです。
お詳しい方や過去に使ったことがある方などいらっしゃいましたら、どこが間違えているのか、ご教示いただけないでしょうか?よろしくお願いいたします。
https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「プラグイン「Posts 2 Posts」がうまく機能しない」には新たに返信することはできません。