posts 2 posts を使用して関連付けた記事をターム毎に表示したい
-
よろしくお願いいたします。
私、PHPのまったくの初心者でまったく分からず右往左往してしまい。トピックで助けていただきたく投稿させていただきます。posts 2 postsでカスタム投稿wheelとcarの投稿記事を関連付けしたものを
single-car.phpにwheelの関連記事をターム別に出力したいと思ってます。Custom Post Type UIを使用してカスタム投稿「wheel」と「car」を作成
functions.phpにて
function my_connection_types() { if ( !function_exists( 'p2p_register_connection_type' ) ) return; p2p_register_connection_type( array( 'name' => 'wheel_to_car', 'from' => 'wheel', 'to' => 'car' ) ); } add_action( 'wp_loaded', 'my_connection_types' );
を作成しました。そこで、
カスタム投稿→ wheel
カスタムタクソノミー→ bland
ターム→hoge1,hoge2,hoge3※表示方法
hoge1
・記事
・記事hoge2
・記事
・記事hoge3
・記事
・記事という風に表示したいと思います。
以下のようですと関連付けた記事がただ一覧として表示されてしまいますので
foreachを使ってループするのかなと漠然と思っているのですが
関連しそうな英語圏のサイトなどググって見たのですが
記述方法をどうして良いのかわかりません。
ご助力お願い致します。<?php // Find connected weeks $connected = new WP_Query( array( 'connected_type' => 'wheel_to_car', // the name of your connection type 'connected_items' => get_queried_object(), 'nopaging' => true, ) ); // Display connected weeks if ( $connected->have_posts() ) : ?> <?php while ( $connected->have_posts() ) : $connected->the_post(); ?> <h3> <?php if ($terms = get_the_terms($post->ID, 'bland')) { foreach ( $terms as $term ) { echo esc_html($term->name) ; } } ?> <?php $title= mb_substr($post->post_title,0,12); echo $title . '...';?> </h3> <?php endwhile; ?> <?php // Prevent weirdness wp_reset_postdata(); endif; ?>
乱文失礼いたします。もし情報が足りなければすぐに足しますので
ご指摘お願い致します。
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「posts 2 posts を使用して関連付けた記事をターム毎に表示したい」には新たに返信することはできません。