投稿から投稿へのプラグインでネストされたループを使用しようとしています。ループは両方とも機能しますが、2番目のネストされたループ($ issue)の後に問題が発生します。$ publicationループに再度アクセスしたいのですが、データは依然として$ issueデータです。
wp_reset_query() single.phpのメインループに戻りますが、これは望ましくありません。
私は使用することができget_posts()、新たなWP_Queryのではなく、私は使用することができるようにしたいですget_template_part()。
2番目の「出版物のタイトル」が号ではなく出版物を返すように、データを出版物のループにリセットするにはどうすればよいですか?
single.php内のコードは次のとおりです。
$publication = new WP_Query( array(
'connected_type'  => 'publication_to_post',
'connected_items' => $post->ID,
'fields'          => 'ids',
'posts_per_page'  => 1,
) );
if ( $publication->have_posts() ) {
while ( $publication->have_posts() ) : $publication->the_post();
    echo '<h2>Publication title = '.get_the_title().'</h2>';
    $pub_id = get_the_ID();
    $issue = new WP_Query( array(
        'connected_type'  => 'publication_to_issue',
        'connected_items' => $pub_id,
        'fields'          => 'ids',
        'posts_per_page'  => 1,
    ) );
    if ( $issue->have_posts() ) {
        while ( $issue->have_posts() ) : $issue->the_post();
            // need to be able to use template parts in here
            echo '<h2>Issue title = '.get_the_title().'</h2>';
        endwhile;
    }
    // This currently returns the issue title, not the publication title
    echo '<h2>Publication title = '.get_the_title().'</h2>';
endwhile;
}