カスタム投稿タイプに年別アーカイブに強制的に複数のカスタム投稿タイプを表示しています。
一部カスタム投稿タイプにACFリピーターで関連を使用しているのですが、
ACFリピーターを使用しているカスタム投稿タイプのみアーカイブで最新1件(この場合はASCなので一番古い記事)しか出ず他のカスタム投稿タイプが表示されません。
##functions.php
function myaction_archive_sortorder( $wp_query ) { if( is_admin() ){ return $wp_query; } if( $wp_query->is_main_query() && $wp_query->is_archive() ){ $wp_query->set( 'posts_per_page',-1 ); $wp_query->set( 'meta_key', 'first_date' ); $wp_query->set( 'orderby', 'meta_value' ); $wp_query->set( 'order', 'ASC' ); $wp_query->set( 'post_status', array('private','publish') ); } return $wp_query; } add_action( 'pre_get_posts', 'myaction_archive_sortorder' );
##ACFの関連を入れているソース
コメントの間を削除すると、全て複数のカスタム投稿タイプが表示されます。
<?php if(get_post_type()=='biography'): ?> <?php $date = date_create( get_field( 'first_date' ) ); echo date_format( $date, 'Y/m/d' ); ?> <?php the_title(); ?> </h4> <?php elseif(get_post_type()=='schedule'&&get_post_status () == 'private' ): ?> <?php if (is_object_in_term($post->ID, 'schedule_cat','scheduleA')): ?> <h4 class="bold"> <?php the_field('sub_title'); ?><?php the_title(); ?> </h4> <?php if(have_rows('event_a_list')): ?> <?php while(have_rows('event_a_list')): the_row(); ?> <dl class="biographybox01"> <dt> <?php $date = date_create( get_sub_field( 'event_a_date' ) ); echo date_format( $date, 'Y/m/d' ); ?> </dt> <dd> <?php $ctm = get_post_meta($post->ID, 'event_a_concept_title', true);?> <?php if(empty($ctm)):?> <p><?php the_sub_field('event_a_concept_title'); ?></p> <?php else : ?> <?php endif;?> <p><?php if(post_custom('event_a_concept_title')): ?> <?php the_sub_field('event_a_concept_title'); ?> <?php endif;?> <!--ここから削除--> <?php $posts = get_sub_field('event_a_places02'); if( $posts ): ?> <?php foreach( $posts as $post): ?> <?php the_field('livehouse_add_place',$post->ID); ?>・<?php the_title(); ?> <?php endforeach; ?> <?php endif; ?> <!--ここまで削除--> </p> </dd> </dl> <?php endwhile; ?> <?php endif; ?> <?php elseif ( is_object_in_term( $post->ID, 'schedule_cat', array( 'scheduleB', 'scheduleC' ) ) ): ?> <h4 class="eventTitle"> <?php the_title(); ?> </h4> <?php if(have_rows('event_b_list')): ?> <?php while(have_rows('event_b_list')): the_row(); ?> <dl class="biographybox01"> <dt> <?php $date = date_create( get_sub_field( 'event_b_date' ) ); echo date_format( $date, 'Y/m/d' ); ?> </dt> <dd> <?php $ctm = get_post_meta($post->ID, 'event_b_concept_title', true);?> <?php if(empty($ctm)):?> <p><?php the_sub_field('event_b_concept_title'); ?></p> <?php else : ?> <?php endif;?> <p><?php if(post_custom('event_b_concept_title')): ?> <?php the_sub_field('event_b_concept_title'); ?> <?php endif; ?> <!--ここから削除--> <?php $posts = get_sub_field('event_b_places02'); if( $posts ): ?> <?php foreach( $posts as $post): ?> <?php the_field('livehouse_add_place',$post->ID); ?>・<?php the_title(); ?> <?php endforeach; ?> <?php endif; ?> <!--ここまで削除--> </p> </dd> </dl> <?php endwhile; ?> <?php endif; ?> <?php endif; ?> <?php elseif ( get_post_type() == 'other' ): ?> <?php if ( is_object_in_term( $post->ID, 'other_cat', array( 'other01', 'other02', 'other03' ) ) ): ?> <div class="otherBlock00"> <h4 class="bold"> <span class="small"><?php $terms = get_the_terms($post->ID,'other_cat'); foreach( $terms as $term ) { echo $term->name; } ?></span> <?php $date = date_create( get_field( 'first_date' ) ); echo date_format( $date, 'Y/m/d' ); ?>発売 <?php if(post_custom('event_concept_title')): ?> <?php the_sub_field('event_concept_title'); ?> <?php endif; ?> 「 <?php the_title(); ?>」</h4> <dl class="otherBox00"> <dd> <?php if(have_rows('other')): ?> <?php while(have_rows('other')): the_row(); ?> <dl> <dt> <img src="<?php the_sub_field('other_jacket'); ?>"> </dt> <dd><?php the_sub_field('other_type'); ?></dd> </dl> <?php endwhile; ?> <?php endif; ?> </dd> </dl> </div> <?php endif; ?> <?php else :?> <?php endif;?>
##関連を使った目的
イベントページなのでイベント会場を関連で表示したいです。
また、関連の箇所のみ削除すると、他のカスタム投稿タイプも一覧として表示されます。
よろしくお願いします。
1件しか出ないというのは、何が1件しか出ないのでしょう。
アーカイブで、ACFリピーターを使用している部分の最新(今回はASCなので一番古い記事)の1件のみの情報しか出ないです
「ACFリピーターで関連を使用しているカスタム投稿タイプ」を投稿タイプAとすると、投稿タイプAのアーカイブを表示する際に、投稿タイプAの記事が1件しか表示されないということですか?
それから、「関連の箇所のみ削除すると、他のカスタム投稿タイプも一覧として表示されます」とのことですが、具体的にどの部分を削除したら正常に動いたのか、削除した部分にコメントを入れていただけますか。
いつも、コメントしていただきありがとうございます。上の質問はその通りです。下の質問に関してはコメントを入れます。
回答1件
あなたの回答
tips
プレビュー