AdvancedCustomFieldsで柔軟コンテンツで関連フィールドについて
-
当方まったくのしょしんしゃで困っております。
AdvancedCustomFieldsのリピーターフィールドで関連フィールドを利用した際
正しく値が取得できるのでしょうか?
例えば
1個目の関連フィールドで
値1、値2
2個目の関連フィールドで
値2、上記のようにするとおのおの出力される個数は指定どおりに出力されるのですが
1個目の関連フィールドのように複数選択すると最初の値(値1)が複数出力されてしまいます。コードはいろいろ調べての切り張りなので無茶苦茶かもしれませんが
以下のように記述してみました。
柔軟コンテンツ→rerotire
レイアウト→17inch
サブフィールド→rerotiretitle(テキストフィールド)、rirotiresize(関連フィールド)内容は投稿記事で他のカスタム投稿の関連記事を取得しています
<?php // check if the flexible content field has rows of data if( have_rows('rerotire') ): // loop through the rows of data while ( have_rows('rerotire') ) : the_row(); // check current row layout if( get_row_layout() == 'inch17' ): ?> <section class="postitem"> <h3><?php the_sub_field("rerotiretitle"); ?></h3> <?php if( have_rows('rirotiresize') ): // check if the nested repeater field has rows of data ?> <?php while( have_rows('rirotiresize') ): the_row(); ?> <?php $posts = get_field('rirotiresize'); if( $posts ): ?> <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?> <?php setup_postdata($post); ?> <a href="<?php the_permalink(); ?>" class="postitem-link"> <section class="postitem-list postitem-list-wheel"> <h3><?php $title= mb_substr($post->post_title,0,12); echo $title . '...';?></h3> <?php endforeach; ?> <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> <?php endif; ?> <?php endwhile; ?> <?php endif; ?> </section> <?php endif; endwhile; else : // no layouts found endif; ?>
ググっても同じような感じの記事が見つけられなく困っております。
よろしくお願いいたします。
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「AdvancedCustomFieldsで柔軟コンテンツで関連フィールドについて」には新たに返信することはできません。